开发者

Calling the finish() method of an Activity from a BroadcastReceiver

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 Acti开发者_如何学运维vity1 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.


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.


You can use Activity2class.finish();

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜