Reputation: 757
I have a notification sending if my app gets new information.
But when I click on the notification it re-opens the activity.
I have only one activity running, so is there a way to close all other activities from the same app, so I just put that in the oncreate and he's gone..
The problem is that there's a timer event that should keep on going while the app is not on top, but everytime I create a new activity, a new timer is created, so the same notification gets send twice making me get allerted two times everytime I get new info..
This is where I create my notification, I guess I have to search it in there, for example the "cleartop" or "singletop" I saw googling but did not work..
Intent resultIntent = new Intent(this, typeof(QuestionsSession));
resultIntent.PutExtra ("targeturl", targeturl);
//resultIntent.SetFlags(ActivityFlags.NewTask | ActivityFlags.SingleTop);
resultIntent.SetFlags (ActivityFlags.ClearTop);
TaskStackBuilder stackBuilder = TaskStackBuilder.Create(this);
stackBuilder.AddParentStack(Java.Lang.Class.FromType(typeof(QuestionsSession)));
stackBuilder.AddNextIntent(resultIntent);
PendingIntent resultPendingIntent = stackBuilder.GetPendingIntent(0, (int)PendingIntentFlags.UpdateCurrent);
// Build the notification
NotificationCompat.Builder builder = new NotificationCompat.Builder(this)
.SetAutoCancel(true) // dismiss the notification from the notification area when the user clicks on it
.SetContentIntent(resultPendingIntent) // start up this activity when the user clicks the intent.
.SetContentTitle("Button Clicked") // Set the title
.SetNumber(TagsCount) // Display the count in the Content Info
.SetSmallIcon(Resource.Drawable.Icon) // This is the icon to display
//.SetContentText(Java.Lang.String.Format("There are {0} new questions.",TagsCount)); // the message to display.
.SetContentText(string.Format("There are new questions.")); // the message to display.
NotificationCompat.InboxStyle inboxStyle = new NotificationCompat.InboxStyle();
builder.SetSound(RingtoneManager.GetDefaultUri(RingtoneType.Notification));
Vibrator v = (Vibrator)GetSystemService (Context.VibratorService);
// Vibrator v = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE);
// Vibrate for 500 milliseconds
v.Vibrate(1000);
// Finally publish the notification
NotificationManager notificationManager = (NotificationManager)GetSystemService(Context.NotificationService);
notificationManager.Notify(1000, builder.Build());
Upvotes: 2
Views: 1001
Reputation: 904
You can add android:launchMode="singleTask"
to the activity-tag in your manifest file. If the activity get's opened again it will then bring the one from the background to the front.
And Timers don't stop when an activity is not visible.
Upvotes: 2