Receive notifications or receive explicit intentions when an action begins

I am developing an application that receives a notification when an Activity selected by the user is launched. For this, the best approach would be to register a BroadcastReceiver for ACTION_MAIN explicit ACTION_MAIN that, as far as I know, do not work (since these Intent have specific goals). Another, possibly less effective, approach is to use the ActivityManager system and a poll on getRunningTask() , which returns a list of all currently running tasks. The survey may be performed by a background service. Watching the changes in this list, I see if the work is working or not, so that my application can receive a notification. The disadvantage, of course, is the survey. I have not tried this yet, but I think this last approach will probably work.

Does anyone know of a more efficient approach or suggestions that are less intense?

+4
source share
1 answer

Why can't you just call getParent() ?

Your child will have it. Activity

 /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); Intent intent = new Intent(); //Create this method in your Parent Activity getParent().onChildCreated(this, intent); } 

It will be in your parent Activity

 public void onChildCreated(Activity child, Intent intent) { /* * Have fun (Edited to pass intent) */ } 
0
source

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


All Articles