简体   繁体   English

在广播接收器中接收时重新启动片段活动

[英]Restarting a fragment activity onreceive in broadcast receiver

I have an ongoing activity but once I receive a broadcast from the android.net.conn.CONNECTIVITY_CHANGE I wish to display to the users that there is no internet connection from an already active fragment activity 我正在进行一个活动,但是一旦收到来自android.net.conn.CONNECTIVITY_CHANGE的广播,我想向用户显示已经活动的片段活动没有互联网连接

Container app = (Container) context.getApplicationContext();
app.recreate();

But the above code does not work in the onreceive method in my broadcast intent reciever and cause a can not cast android app to fragment activity Container. 但是上面的代码在我的广播意图接收器中的onreceive方法中不起作用,并且导致无法将android应用onreceive转换为活动容器。 How do I fix this? 我该如何解决?

I wish to display to the users that there is no internet connection from an already active fragment activity 我希望向用户显示, 已经活动的片段活动没有互联网连接

Try having a "BaseFragmentActivity" that has a broadcast receiver member that does this. 尝试让具有广播接收器成员的“ BaseFragmentActivity”执行此操作。 And each FragmentActivity in your app should extend it. 应用程序中的每个FragmentActivity都应该对其进行extend

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM