Android which Intent flags are recommended for notifications triggered operations

I am having a specific problem with an application that has several actions. I have a screen manager associated with the service. Server polling service for data. The screen manager launches Activity A, B, or C based on the data. It will also allow the user to choose to display other activities or he can automatically change the action based on new data from the service. Currently, the entire navigation system works fine, and if the user clicks "Home", the corresponding activity returns to the foreground when the user clicks the application icon on the Android main screen or in the list of recently launched applications.

Then I had to implement a new function to display the icon and notification. At first I implemented this, only showing a notification when the actions were no longer visible, setting it in each of the onPause activities. It worked like a charm and gave the user a third option to re-display the application after pressing the "Home" button. However, if the data from the server (when the application is not displayed) forces the screen manager to update the displayed action. I'm having problems. I think that my activity stack is spinning up. Since then, I tried a slightly different model in which the screen manager processes notifications and always displays a notification, updating it with a new intent whenever activity is updated, but it still does not cut it.

When the application is minimized and data changes, I see that the screen manager calls startActivityForResult for a new action, and it looks like Android knows that we are minimized and do not display Activity. Then I can also call the screen manager call to complete the old top activity.

Currently, for each activity, the flag is set to singleTop in the manifest and FLAG_ACTIVITY_SINGLE_TOP in the code. When the data has not changed on the server, I pull the application back using any of the above, I get what I expect, and Activity onNewIntent is called. However, when the data has been changed and the user calls the application through a notification, he calls the onCreate actions. The Activity starts and starts, but then dropping it returns me to what looks like another instance of the same Activity, not an exit. I just looked carefully at my logarithm, and I see 2 calls to Activity onResume, but after that there are no doubles.

It seems to me that maybe I just missed something simple, like another flag of intent in the intention of notification? Thanks for any ideas!

+8
android notifications
Nov 08 '10 at 23:35
source share
1 answer

What kills me is the data from the server, which changes when it is not displayed.

I have no idea what that means.

It seems to me that maybe I just missed something simple, like another flag of intent in the intention of notification?

I used Intent.FLAG_ACTIVITY_CLEAR_TOP|Intent.FLAG_ACTIVITY_SINGLE_TOP to solve the problem "returns me to what seems like another instance of the same task", but in my case I had a single-task application.

The documentation for FLAG_ACTIVITY_CLEAR_TOP also says:

"This launch mode can also be used for a good effect in combination with FLAG_ACTIVITY_NEW_TASK: if it is used to start the root activity of a task, it will launch the current executable instance of this task in the foreground and then clear it to. This is especially useful, for example, when starting an activity from the notification manager. "

There is also FLAG_ACTIVITY_REORDER_TO_FRONT :

"For example, consider a task consisting of four activities: A, B, C, D. If D calls startActivity () with an intent that resolves activity component B, then B will be moved to the beginning of the history stack, with this resulting order: A , C, D, B. This flag will be ignored if FLAG_ACTIVITY_CLEAR_TOP is also specified. "

Perhaps one of these templates suits your needs.

+5
Nov 09 2018-10-11T00:
source share



All Articles