Note that there are some explanatory texts on larger screens.

plurals
  1. POResult error using BroadCast Receiver
    primarykey
    data
    text
    <p>I am currently developing Web Crawling in android</p> <p>I have a code to check whether there is internet connection or not </p> <p>but if i turned the mobile network the application suddenly error wanted to force close here are some code :</p> <pre><code>package thesis.carlo; @Override protected void onHandleIntent(Intent intent) { // TODO Auto-generated method stub receiver = new ConnectivityReceiver(); registerReceiver(receiver, new IntentFilter( ConnectivityManager.CONNECTIVITY_ACTION)); Notification note = new Notification(R.drawable.target, "Crawling", System.currentTimeMillis()); Intent i = new Intent(this, LoadingActivity.class); i.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP); PendingIntent pi = PendingIntent.getActivity(this, 0, i, 0); note.setLatestEventInfo(this, "Focused Crawling","In Progress Crawling...", pi); note.flags |= Notification.FLAG_NO_CLEAR; startForeground(1337, note); this.crawls(resultMap, keywords); stopForeground (true); this.showResult(urlsList, valueList); result = Activity.RESULT_OK; } public void showResult(List urlList, List valList) { Intent i = new Intent(this, ResultActivity.class).setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); i.putStringArrayListExtra("urlsList", (ArrayList&lt;String&gt;) urlList); i.putParcelableArrayListExtra("valueList", (ArrayList&lt;? extends Parcelable&gt;) valList); startActivity(i); } private String getNetworkStateString(NetworkInfo.State state) { String stateString = "Unknown"; switch (state) { case CONNECTED: stateString = "Connected"; break; case CONNECTING: stateString = "Connecting"; break; case DISCONNECTED: stateString = "Disconnected"; break; case DISCONNECTING: stateString = "Disconnecting"; break; case SUSPENDED: stateString = "Suspended"; break; default: stateString = "Unknown"; break; } return stateString; } public void onDestroy() { unregisterReceiver(receiver); super.onDestroy(); } private class ConnectivityReceiver extends BroadcastReceiver { @Override public void onReceive(Context context, Intent intent) { NetworkInfo info = intent .getParcelableExtra(ConnectivityManager.EXTRA_NETWORK_INFO); if (null != info) { String state = getNetworkStateString(info.getState()); String stateString = info.toString().replace(',', '\n'); Log.i("ConnTest", info.getTypeName()); Log.i("ConnTest", state); Log.i("ConnTest", info.toString()); if(state.equals("Disconnected")){ stop(); } } } } public void stop(){ stopService(new Intent(this, CrawlingActivityService.class)); startActivity(new Intent(this, ErrorActivity.class).setFlags(Intent.FLAG_ACTIVITY_NEW_TASK)); stopForeground (true); } </code></pre> <p>}</p> <p>I dont know why the onReceive method didn't invoke when I turned of the mobile network</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload