I have two apps that I made, and am trying to send an intent from one to the other but the intent is never getting to the onReceive()
however this problem is only one way. The first app can send to the second but the second cannot send back info. I am using a different intent action to send from the second to the first but otherwise they are identical. Any ideas on why this might not be working? I have tried everything I can think of and read most of the posts I could find on here and to no avail.
It's not crashing or giving me any indications as to what is happening in the logcat it's just doing nothing.
send function
private void sendFinishLog(String ID, String Cond)
{
Log.d("me", "send finish log");
Intent logIntent = new Intent();
logIntent.putExtra("ID", ID);
logIntent.putExtra("Cond", Cond);
logIntent.setAction("com.me.intent.finishlog");
Log.d("me","logIntent : " + logIntent.toString()
+logIntent.getExtras().toString());
sendBroadcast(logIntent);
}
receive class
public class LogReceiver extends BroadcastReceiver {
public static ArrayList<LogDataHolder> logData = new ArrayList<LogDataHolder>();
private boolean found;
static SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
private static String lasttime;
private static String now = "Boot time";
@Override
public void onReceive(Context cont, Intent logIntent)
{
Log.d("me","On receive");
etc.....
}
Receiving app manifest
<!-- for receiving logs -->
<receiver
android:name = "LogReceiver"
android:enabled="true">
<intent_filter>
<action android:name="com.me.intent.finishlog" />
</intent_filter>
</receiver>
Broadcast intents are a mechanism by which an intent can be issued for consumption by multiple components on an Android system. Broadcasts are detected by registering a Broadcast Receiver which, in turn, is configured to listen for intents that match particular action strings.
A simple solution to this problem is to call the registerReceiver() in your Custom Application Class. This will ensure that your Broadcast receiver will be called only one in your entire Application lifecycle.
something like:
public void onResume() {
IntentFilter filter = new IntentFilter();
getActivity().registerReceiver(mLogReceiver,filter);
}
and for un-register:
public void onPause() {
getActivity().unregsiterReceiver(mLogreceiver);
}
edit: i just figured that your LogReceiver-class has no constructor neither. you will need to write one aswell:
private LogReceiver mLogReceiver = new LogReceiver() {
and after that you can use the onReceive-method like you have it already in your code.
Try it again like this. The category may need to be added
<receiver
android:name = "LogReceiver"
android:enabled="true">
<intent-filter>
<action android:name="com.me.intent.finishlog" />
<category android:name="android.intent.category.DEFAULT"/>
</intent-filter>
</receiver>
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