I have an activity used to clear some static variables and open the browser if a notification is clicked, and if the notification is dismissed by swiping it, the activity just close itself without opening the browser, i've managed to do this by using a extra boolean in the intent used to start the activity.
Since this activity is just for cleaning the variables and occasionally opening the browser, once it finish its work it close itself with finish(), but after that finish is called... the app randomly start another activity (the main menu of the app).
I have no idea about what could be causing this strange thing.
The code that i use to create the notification is this:
Intent openNotification = new Intent(cText,LaunchBrowser.class).putExtra("url", notifica.getURL()).putExtra("open", true);
Intent closeNotification = new Intent(cText,LaunchBrowser.class).putExtra("open", false));
NotificationCompat.Builder notificBuilder =
new NotificationCompat.Builder(cText)
.setContentTitle("New Notification")
.setContentText(notifica.getText())
.setSmallIcon(R.drawable.ic_launcher)
.setContentIntent(PendingIntent.getActivity(cText, getUniqueID(), openNotification, PendingIntent.FLAG_CANCEL_CURRENT))
.setDeleteIntent(PendingIntent.getActivity(cText, getUniqueID(), closeNotification, PendingIntent.FLAG_CANCEL_CURRENT))
.setAutoCancel(true);
((NotificationManager)getSystemService(NOTIFICATION_SERVICE)).notify(0, notificBuilder.build());
currentNotification = notifica.getText();
LaunchBrowser class:
public class LaunchBrowser extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_launch_browser);
onNewIntent(getIntent());
}
@Override
protected void onNewIntent(Intent intent) {
super.onNewIntent(intent);
WebNotificChecker.currentNotification = "";
WebNotificChecker.currentNotificationCounter = 0;
if(intent.getBooleanExtra("open",false)){
startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(intent.getStringExtra("url"))));
}
finish();
}
}
The code does what it should do, the only problem is that when i swipe away the notification from the phone home the main menu open itself, and... it actually doesen't make sense to me since the MainActivity class is never written on the LaunchBrowser code nor in the part that create the notification...