zer0stimulus
zer0stimulus

Reputation: 23646

Android: How to pass Intent via startActivity() to a running Activity?

Say MyService and MyClient are both running, although MyClient is currently in the background. If MyService sends an Intent to MyClient via:

Intent i = new Intent(MYService.this, MyClient.class);
i.setAction("com.test.MyService.ACTION_SERVICE");
i.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(i);

How do I get this Intent in MyClient? Running this code triggers onResume() in MyClient, but because it's already running, calling getIntent() returns the Intent that initially created MyClient, which is always android.intent.action.MAIN

Upvotes: 3

Views: 4367

Answers (1)

Falmarri
Falmarri

Reputation: 48587

override onNewIntent() and make sure you flag the intent so that it doesn't start a new instance of your activity

Upvotes: 8

Related Questions