How to find out the number of operations of my application?

I have several actions in my application. Please consider the following case ...

Action A calls Acitivy BB calls C. When the user presses the C key, generates a notification and proceeds to B. Now press again to display A, and the back key will appear again and a notification will appear ... Now that the user clicks the notification icon, C activity is loading .... Until this part is correct .... Now the user clicks back, I start operation A using my code when C was loaded from Notification.

Another case, Activity A calls Acitivy B. B calls C. When the user presses the C key, generates a notification and proceeds to B. Now the user presses HOME KEY. Then after some time selects the notification icon, it displays the action C. Now the user presses the Back Key, by default it displays Activity B (which I want) .... But my code (like C, loaded from the notification) ... im display activity A (n the user presses back, then activity B is displayed).

I want to find out the Activity Count of my own application so that I can avoid executing my code in order to run Activity A (if it's not 1).

So far I have done this using the following code

ActivityManager actM = (ActivityManager) getSystemService(ACTIVITY_SERVICE); List<ActivityManager.RunningTaskInfo> listm = actM.getRunningTasks(1); int iNumActivity = listm.get(0).numActivities; 

But using this code requires the use of GET_TASKS permission ... I don’t like this because I do not track any other data about application data / activity.

How to fix it? Is there any other way to achieve this?

EDIT How do I know the amount of activity of my own application?

+4
source share
2 answers

Just counting is a problem. create a static variable count in the class say Constants. or maybe three of them ... and whenever you go to a specific class ... create the appropriate static public variable.

Edit: you can also save the number of actions in the general settings.

+1
source

One way is to push the activity shown on the stack (singleton) from onResume () in each of your actions and press it when the back button is pressed. That way, whenever you click Back, you will know the current stack of Actions. Since this will be used by all classes, this will help preserve the values.

0
source

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


All Articles