0

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...

Celeste Capece
  • 1,306
  • 2
  • 11
  • 20
  • 1
    Which *other activity* do you mean? Please can you show the full code of the activity that launches the browser? – X09 Sep 10 '16 at 08:39
  • Added some details and the full code of LaunchBrowser, anyway the activity launched after that LaunchBrowser close itself is the main menu of the app (called MainActivity) – Celeste Capece Sep 10 '16 at 08:51
  • In the activity hierarchy, is **MainActivity** a parent of **LaunchBrowser**? – X09 Sep 10 '16 at 08:56
  • I'm not sure, anyway they should be totally unrelated, the notification that open **LaunchBrowser** is created from a service, so it's not like **MainActivity** is starting **LaunchBrowser** – Celeste Capece Sep 10 '16 at 09:00
  • is there any code/callback you have return when notification is dismissed? – Nikhil Sep 10 '16 at 09:24
  • how should i check it? – Celeste Capece Sep 10 '16 at 09:26
  • In your notification class. Because if your dismissing the notification it should not do anything unless your have written something for it. – Nikhil Sep 10 '16 at 09:31
  • when I dismiss the notification I start **LaunchBrowser** – Celeste Capece Sep 10 '16 at 09:47

0 Answers0