1

I've built a small app. The only thing it does is, catch an outgoing call and show some activity when it happens. There is just an Activity and a BroadcastReceiver.

I wanted to integrate my code with another application, I removed the BroadcastReceiver from the Manifest.xml and created (and registered) it dynamically from the main activity. My receiver fired well but the activity is not shows up.

What is the difference between the two methods?

How can I make the activity to show up?

from MainActivity.java:

callInterceptor = new InterceptOutgoingCall();
IntentFilter callInterceptorIntentFilter = new IntentFilter("android.intent.action.NEW_OUTGOING_CALL");
callInterceptorIntentFilter.setPriority(100);
registerReceiver(callInterceptor,  callInterceptorIntentFilter);

and from the function receiver.onReceive(Context,Intent):

Intent alertIntent = new Intent(context, AlertActivity.class);
alertIntent.putExtra("callnumber", phonenbr);
alertIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(alertIntent);

my activity is declared in the manifest like this:

<activity android:name=".AlertActivity" 
            android:screenOrientation="portrait"/>
Abdul Wasae
  • 3,614
  • 4
  • 34
  • 56
Bush
  • 2,433
  • 5
  • 34
  • 57

1 Answers1

1

I found the answer at two threads:

  1. Android launch an activity from a broadcast receiver

  2. Activity started from notification opened on top of the activity stack

In the manifest, the activity should be declared with android:taskAffinity. And when starting the intent I had to add a flag = Intent.FLAG_ACTIVITY_NEW_TASK

Community
  • 1
  • 1
Bush
  • 2,433
  • 5
  • 34
  • 57