Callback from BroadcastReceiver beetwen Apps?

I want to allow other Apps to integrate with mine and I'm writing a dummy "consumer" app but I cant achieve to return a callback to notify the "consumer" app if everything went well.

So my DUMMY_APP has a simple layout with 2 buttons a success call, and a call with a wrong EXTRA param. To make DUMMY_APP to call MAIN_APP I use sendBroadcast

// MainActivity class

private static final String REQUIRED_ACTION = "com.basetis.afr.intent.action.INIT_TEXT_FLOW";

onCreate....
    Button btnSuccess = (Button)findViewById(R.id.button_success_call);
    btnSuccess.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            i.setAction(REQUIRED_ACTION);
            i.putExtra(Intent.EXTRA_TEXT, textToBeRead);
            sendBroadcast(i);
        }
    });

So MAIN_APP has the corresponding BroadcastReceiver that is receiving fine.

// BlinkingReadReceiver class
private static final String CALLBACK_CALL_AFR_ACTION = "com.basetis.afr.intent.action.CALLBACK_CALL_AFR_ACTION";

@Override
public void onReceive(Context context, Intent intent) {
    Intent i = new Intent();
    i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);

    Log.d(TAG, "SUCCESS send callback");
    i.setAction(CALLBACK_CALL_AFR_ACTION);
    i.putExtra(CALL_AFR_SUCCESS_EXTRA, CALL_AFR_SUCCESS_EXTRA_DESC);
    i.setType("text/plain");

    context.sendBroadcast(i);
}

So the DUMMY_APP BroadcastReceiver never receive nothing :(

So I configured Manifests like that:

DUMMY_APP

        <receiver android:name=".MainBroadcastReceiver" android:enabled="true">
            <intent-filter>
                <action android:name="com.basetis.afr.intent.action.CALLBACK_CALL_AFR_ACTION"></action>
            </intent-filter>
        </receiver>

MAIN_APP

    <receiver android:name=".BlinkingReadReceiver" android:enabled="true">
        <intent-filter>
            <action android:name="com.basetis.afr.intent.action.INIT_TEXT_FLOW"></action>
        </intent-filter>
    </receiver>

Sometimes I receive this error (afrsender is de DUMMY_APP) but seems sort of random...

Performing stop of activity that is not resumed: {com.basetis.afrsender.afrsender/com.basetis.afrsender.afrsender.MainActivity}
java.lang.RuntimeException: Performing stop of activity that is not resumed

Any suggestions about how to achieve this two way App communication?

Thank you very much.

Answers


As stated in the document

Starting from Android 3.1, the system's package manager keeps track of applications 
that are in a stopped state and provides a means of controlling their launch from 
background processes and other applications.

That means that till the app is not started manually by the user your app will be in force stop state and it won't receive any broadcast. That's why your dummy app is not receiving and broadcast sent by main app. Check here for more reference


Need Your Help

How to open multiple consoles in multiple tabs in Eclipse?

java eclipse console perspective

I am using Eclipse Version: Helios Release for a Java application. I need to run multiple instances of same application and want easy visibility of multiple consoles.

Oracle's pro*C compiler and gnu C (__builtin_va_list, __attribute__, etc)

c oracle compilation gnu oracle-pro-c

I'm compiling a database library with proC which converts the .ppc library file to a .c file that gcc can use. However, I'm getting a lot of errors in proC like the following