Skip to content Skip to sidebar Skip to footer

Is There An Android Intent That Resumes The App Or Opens It Again?

In my android app, this code will open/resume a activity NotificationManager notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);

Solution 1:

Ok, here is the hack way I got, maybe someone can improve on it.

publicBoolean paused = false;

@OverrideprotectedvoidonPause() {
    super.onPause();
    paused = true;
}

@OverrideprotectedvoidonResume() {
    super.onResume();
    paused = false;
}

privatevoidsetUpScreen() {
    if (getIntent().getExtras() != null) {
        // ran normally
    } else {
        // opened from notificationfinish();

        // open default activityIntent myIntent = newIntent(this, SplashScreen.class);
        startActivity(myIntent);
    }
}

in the async

@OverrideprotectedvoidonPostExecute(List<CompareResult> compareResults) {


    if (context.paused) {
        showNotification();
    }
}

privatevoidshowNotification() {
    NotificationManagernotificationManager= (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);

    IntentnotIntent=newIntent(context, SpeciesScreen.class);
    notIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);

    PendingIntentpIntent= PendingIntent.getActivity(context.getApplicationContext(), 0, notIntent, 0);

    Notificationnoti=newNotification.Builder(context)
    .setContentTitle("Scan Complete")
    .setSmallIcon(R.drawable.ic_launcher)
    .setContentIntent(pIntent)
    .setAutoCancel(true)
    .build();

    notificationManager.notify(0, noti); 
}

Post a Comment for "Is There An Android Intent That Resumes The App Or Opens It Again?"