简体   繁体   中英

Android, killing an Activity from another Activity from GCM message

I've currently wrote an app that receives a GCM message and stores it in a database then creates an alertDialog to show above any app what the new message is, the only problem i have is if a new message is received before the current alertDialog is closed you don't get to see the new message, if i sit and close each message its fine.

So i think what ive been trying is to ask 'is the alertDialog showing...if not show the message, if its already showing close it and open a new one with the new message'.

Does this sound feasible?

Cheers Mark

I would recommend using a notification rather than an alert dialog for showing incoming messages. The NotificationManager lets you set an id and tag when you post a notification. Then if you later post one with the same id and tag, the existing one will be updated.

On Lollipop (and newer) devices you can even get a similar effect to what you describe with the notification coming up on top of the current app using heads up notifications: http://developer.android.com/guide/topics/ui/notifiers/notifications.html#Heads-up

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM