I get this issue in ICS, but not in previous versions:
From App1, I am sending broadcast and trying to receive it in App 2 activity. But the onReceive is never called in App 2's activity.
I cannot understand what is that block's onReceive from getting called, though I have specified everything correctly.
I run the BroadcastReceive first and then BroadcastSend
Any help which would help me resolve this is much appreciated.
App1 send activity
public class BroadcastSend extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Intent i = new Intent();
i.setAction("edu.ius.rwisman.custom.intent.action.TEST");
i.putExtra("url","ww.ius.edu");
sendBroadcast(i);
}
App 2 receive activity
public class BroadcastReceive extends BroadcastReceiver{
// Display an alert that we've received a message.
@Override
public void onReceive(Context context, Intent intent){
System.out.println("Inside onReceive");
String url = intent.getExtras().getString("url");
Toast.makeText(context, "BroadcastReceive:"+url, Toast.LENGTH_SHORT).show();
}
Manifest of App 2
<?xml version="1.0" encoding="utf-8"?>
<application android:icon="@drawable/icon" android:label="@string/app_name">
<receiver android:name="edu.ius.rwisman.BroadcastReceive.BroadcastReceive" android:enabled="true" android:exported="true">
<intent-filter>
<action android:name="edu.ius.rwisman.custom.intent.action.TEST"/>
</intent-filter>
</receiver>
</application>
There are two ways to make a broadcast receiver known to the system: One is declare it in the manifest file with this element. The other is to create the receiver dynamically in code and register it with the Context. registerReceiver() method.
onReceive always run in the UI thread? Yes.
When it runs on the main thread you should never perform long-running operations in it (there is a timeout of 10 seconds that the system allows before considering the receiver to be blocked and a candidate to be killed). You cannot launch a popup dialog in your implementation of onReceive().
In ICS you won't receive broadcasts until your app is started manually at least once.in Android 3.1+, apps are in a stopped state if they have never been run, or have been force stopped. The system excludes these apps from broadcast intents. They can be included by using the Intent.FLAG_INCLUDE_STOPPED_PACKAGES flag like this..
i.addFlags(Intent.FLAG_INCLUDE_STOPPED_PACKAGES);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With