从 BroadcastReceiver 调用 Activity 的 finish() 方法
我有 2 个活动(Activity1、Activity2)和一个 BroadcastReceiver 类,
假设我们现在位于 Activity2,我在其中设置了一个 AlarmManager 以在特定时间运行。
有没有办法在BroadcastReceiver的onReceive()中调用Activity2的finish()方法?
我的目标是从 Activity2 返回到 Activity1,而不在 onRecieve() 中启动新的 Intent。
注意:BroadcastReceiver类没有在Activity2的Activity中注册。它注册在AndroidManifest.xml中。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以在 onReceive 方法上调用 finish()。请记住在 OnDestroy 上取消注册您的侦听器。如果 Activity1 已经初始化,Android 将激活 Activity1。我假设您正在按顺序打开活动。
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.
您可以使用 Activity2class.finish();
You can use Activity2class.finish();