Android: How to pass Intent via startActivity () to current activity?

Say MyServiceand MyClient, both are running, although it MyClientis currently in the background. If MyServicesends the intention in MyClientthrough:

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 to get this intention in MyClient? Running this code calls onResume () in MyClient, but since it is already running, the call getIntent()returns the Intent originally created by MyClient, which alwaysandroid.intent.action.MAIN

+3
source share
1 answer

override onNewIntent () and make sure you mark the intention so that it does not start a new instance of your activity.

+7
source

Source: https://habr.com/ru/post/1758852/


All Articles