Ragunath Jawahar
Ragunath Jawahar

Reputation: 19723

Starting another application from broadcast receiver

I am trying to start an activity from a Receiver after the device boot:

Intent intent = new Intent(Intent.ACTION_MAIN);
intent.setComponent(ComponentName.unflattenFromString("other.apps.package.name/.ActivityName"));
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intent.addCategory(Intent.CATEGORY_LAUNCHER); 
context.startActivity(intent);

This code just works fine when I call it from my activity however it fails when my BroadcastReceiver executes it after bootup. My Logcat shows:

ActivityNotFoundException: Have you declared the activity in your AndroidManifest.xml?

Any pointers will be greatly appreciated. Thanks in advance.

Upvotes: 2

Views: 1166

Answers (3)

ud_an
ud_an

Reputation: 4921

Intent intent = new Intent(context, activity.class); intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); context.startActivity(intent);

i think this 3 lines only needed and the context will be the context u receive in broadcast receiver.

Upvotes: 1

jainal
jainal

Reputation: 3021

I think the problem is in the following Line.what is the name of your Activity?is it "ActivityName"?Also Check package name.

intent.setComponent(ComponentName.unflattenFromString("other.apps.package.name/.ActivityName"))

Upvotes: 0

coder_For_Life22
coder_For_Life22

Reputation: 26971

You probably spelled or made a error when you declared your Activity in your manifest. Make sure you put it in there and spelled everything correctly

Upvotes: 0

Related Questions