android广播起activity,从Android的BroadcastReceiver调用Activity方法
尝试这个代码:你的互联网丢失类的broadcastreceiver类:public class InternetLostReceiver extends BroadcastReceiver{@Overridepublic void onReceive(Context context, Intent intent) {context.sendBroadcast(new Intent("INTERNE
尝试这个代码:
你的互联网丢失类的broadcastreceiver类:
public class InternetLostReceiver extends BroadcastReceiver{
@Override
public void onReceive(Context context, Intent intent) {
context.sendBroadcast(new Intent("INTERNET_LOST"));
}
}
在你的活动中添加这个呼叫广播:
public class TestActivity extends Activity{
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
registerReceiver(broadcastReceiver, new IntentFilter("INTERNET_LOST"));
}
BroadcastReceiver broadcastReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
// internet lost alert dialog method call from here...
}
};
@Override
protected void onDestroy() {
super.onDestroy();
unregisterReceiver(broadcastReceiver);
}
}
更多推荐
所有评论(0)