开发者

Notification to not reload app in android

I am currently developing an android app which uses the android web browser and notifications.

What I want to be able to do is the user clicks on an item which loads the android web browser and makes a notification in the notification bar as well.

The user should be on the browser when they go the notification, so when the user is on the browser and they click on the notification I want the notification to perform its task but not redisplay the app activity instead just return to where the user was on the browser.

I've tried setting the different flags on the activity but none of them seem to make any differ开发者_Python百科ence.

Thanks for any help you can provide.


According to the following quote from the Android documentation, it sounds like there isn't a way to do some kind of background task without starting an activity when a user clicks a notification. Although you may want to look into sending an Intent to a Service. I've have not tried that before so I can't say whether it works or not.

A notification always starts an activity as a new task (that is, it puts FLAG_ACTIVITY_NEW_TASK in the intent it passes to startActivity())

The documentation also suggests you could have a dedicated activity that could perform the copy paste, and then the user could simply press back to get back to the browser:

For example, when the user receives a Calendar notification, choosing that notification starts a special activity that displays a list of upcoming calendar events — this view is available only from the notification, not through the Calendar's own user interface. After viewing this upcoming event, to ensure that the user pressing the BACK key will return to the activity the user was in when they picked the notification, you would make sure this dedicated activity does not have the same task affinity as the Calendar or any other activity. (You do this by setting task affinity to the empty string, which means it has no affinity to anything.)


To get round this as I did not want to have a service running in the background to perform this simple task what I have done is called the method at the end of the activity that the notification calls.

I call moveTaskToBack(true); which places the task into the background. As if the user presses the home button.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜