-1
Android策略如果廣播工作超過10秒,將發生ANR對話框。爲什麼在Android上發生ANR Intent消息廣播?
所以,我覺得我的播出工作超過10秒。因爲許多人在播放這個節目
我的廣播當我的設備上的CONNECTIVITY_ACTION
。
@Override
public void onReceive(Context context, Intent intent) {
String action = intent.getAction();
WifiManager wifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo activeNetwork = cm.getActiveNetworkInfo();
int iNetworkType = (activeNetwork == null) ?-1: activeNetwork.getType(); //null check
if (action.equals(ConnectivityManager.CONNECTIVITY_ACTION)) {
new getPubIp().execute(); //Execute AsyncTask
ConnectivityManager connectivityManager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
if (iNetworkType == connectivityManager.TYPE_ETHERNET) {//connect ethernet
EthernetConnectTimeDB ethernet;
ethernet = new EthernetConnectTimeDB();
ethernet.start(); //DB Insert work.
SystemClock.sleep(500); // sleep
MainActivity.display("value", "value", value"); //display UI
}
}
}
這個接收器很多工作。數據庫工作,顯示工作,asynctask工作。
如何解決在Android上發生ANR對話框?
謝謝。