Show alert on admission

How can I display a warning when a push notification comes from C2DM or GCM. Now I'm showing status bar notifications. So, how can I get a notification as a warning.

+4
source share
2 answers

Having a dialog box in the middle of what the user is doing is a hostile task. What if they play Angry Birds and you just destroyed them? Only a platform can and should get away with it.

Use the notification area, for example Google, if you don’t have an application right now (your activity is in working order). Then simply use this activity context to open AlertDialog() . You can determine if the operation works by overriding onResume() and onPause() - everything that happens between them is the time of your activity.

AlertDialog can be displayed as follows:

 new AlertDialog.Builder(Ctxt) //Use an activity object here .setMessage(R.string.MyMessageID) //Provide a message here... A string or a string ID will do .setCancelable(true) //If you want them to be able to dismiss with a Back button .setNegativeButton(R.string.IDS_NO, null) //No action on NO, right? .setPositiveButton(R.string.IDS_YES, OnYesClickListener) //Plug your own listener... .create() .show(); 

For a simple Yes / No message / dialog, AlertDialog enough. For a more complex user interface, derive a class from Dialog and create your own layout.

+6
source

For notification you need to write the code in

generateNotification (context context, String message)

in this method.

thanks

+1
source

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


All Articles