问题
I have 2 Activities (Activity1, Activity2) and a BroadcastReceiver class
Assume that we are now on Activity2, where I set up an AlarmManager to run at a specific time.
Is there a way to call the finish() method of Activity2 within the onReceive() of the BroadcastReceiver?
My goal is to return to Activity1 from Activity2 without starting a new Intent in onRecieve().
Note: The BroadcastReceiver class is not registered within the Activity of Activity2. It is registered in the AndroidManifest.xml.
回答1:
You can call finish() on the onReceive method. Do remember to unregister your listener on the OnDestroy. If Activity1 has already been initialized Android will activate Activity1. I am assuming you are opening the activities in a sequence.
回答2:
You can use Activity2class.finish();
来源:https://stackoverflow.com/questions/5153630/calling-the-finish-method-of-an-activity-from-a-broadcastreceiver