Android notification update activity

My IntentService starts at 9:00 and repeats every hour.

It works with AsyncTask, which creates a BUNDLE.

The IntentService should show Actvity in a dialog (for example, Viber for messages) that shows a piece of data in this BUNDLE, and it should create a notification that shows the same piece of data. If the user clicks on the notification, he will launch the second action, which will display all the data from BUNDLE.

The problem is this: IntentService does its job, shows activity, and creates a notification. But the problem is that the user did not use the smartphone. An hour later, the IntentService will restart, and its operation will create a new BUNDLE.

WITH THE CODE BELOW, NOTICE IS JUSTIFIED BUT NOT ACTIVITY. If the user now uses a smartphone, he will see the data of the old BUNDLE in his activity, and not the new BUNDLE. I SHOULD ELIMINATE THIS ACTIVITY, obviously, if the user clicks on the notification, even updated activity should be updated.

In "IntentService", "onHandleIntent (intent intent)" starts the dialog activity:

Intent myIntent = new Intent(this.myContext, *DIALOG_ACTIVITY*); myIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK); myIntent.putExtras(**BUNDLE**); this.myContext.startActivity(myIntent); 

and creates a notification:

 Intent notifyIntent = new Intent(context, *SECOND_ACTIVITY*); notifyIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK); notifyIntent.putExtras(**BUNDLE**); PendingIntent pIntent = PendingIntent.getActivity(context, 0, notifyIntent, PendingIntent.FLAG_UPDATE_CURRENT); NotificationCompat.Builder builder = new NotificationCompat.Builder(context); builder.setSmallIcon(icon); builder.setContentTitle(title); builder.setContentText(longText); builder.setWhen(System.currentTimeMillis()); builder.setContentIntent(pIntent); Notification n = builder.build(); n.flags |= Notification.FLAG_AUTO_CANCEL; NotificationManager nm = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE); nm.notify(idNotification, n); 

In the Android manifest, DIALOG_ACTIVITY:

  <activity android:name="com.example.sample.DIALOG_ACTIVITY" android:launchMode="singleTask" android:taskAffinity="" android:excludeFromRecents="true" android:theme="@android:style/Theme.Dialog"> </activity> 

and SECOND_ACTIVITY:

  <activity android:name="com.example.sample.SECOND_ACTIVITY" android:theme="@style/Theme.AppCompat" android:parentActivityName="com.example.sample.MainActivity" > <!-- Parent activity meta-data to support API level 7+ --> <meta-data android:name="android.support.PARENT_ACTIVITY" android:value="com.example.sample.MainActivity" /> </activity> 

IDEAS?

THANKS A LOT!

0
source share
1 answer

Try the following:

 myList.setAdapter(adapter); NotificationManager nm = (NotificationManager)getSystemService(Context.NOTIFICATION_SERVICE); Notification notification = new Notification(android.R.drawable.stat_sys_warning, "This is an important msg", System.currentTimeMillis()); ntent intent = new Intent(MainActivity.this, MainActivity.class); PendingIntent pendingNotify = PendingIntent.getActivity(MainActivity.this, 0, intent, 0); notification.setLatestEventInfo(MainActivity.this, "This is a demo", "Continue with yourwork.",pendingNotify); nm.notify(0, notification); 
0
source

All Articles