I am currently working on GCM (Google Cloud message), it allows the user to click the message on the user device. And I would like to fulfill the following requirement:
if the user has already entered the application, ignore it
If the user has not logged into the application, click on the notification to enter the application
And the work flow of my application:
- WelcomePage (loading json and creating a dataset from it) => MainPage (display base in the dataset)
Notification Processing Code
private void sendNotification(String msg) { mNotificationManager = (NotificationManager) this.getSystemService(Context.NOTIFICATION_SERVICE); String notifyMsg = ""; JSONTokener tokener = new JSONTokener(msg); if (tokener != null) { try { notifyMsg = new JSONObject(tokener).getString("msg"); } catch (JSONException e) { // TODO Auto-generated catch block e.printStackTrace(); } } Intent myintent = new Intent(this, WelcomePageActivity.class); myintent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP); PendingIntent contentIntent = PendingIntent.getActivity(this, 0, myintent, PendingIntent.FLAG_UPDATE_CURRENT); NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this) .setSmallIcon(R.drawable.ic_launcher) .setContentTitle(getResources().getString(R.string.notification_title)) .setStyle(new NotificationCompat.BigTextStyle() .bigText(notifyMsg)) .setContentText(notifyMsg) .setContentIntent(contentIntent); mNotificationManager.notify(NOTIFICATION_ID, mBuilder.build()); }
The problem is that if I use the WelcomePageActivity class, it will create a new action, if I am on the main page, how can I customize the code according to my requirement?
thanks
android android-intent push-notification notifications android-notifications
user782104
source share