Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
681 views
in Technique[技术] by (71.8m points)

android - Preserve back activity while clicking notification

My problem is like that: When I'm pressing the notification i got, some activity is open, lets say activity number 3. But when I press the back button, I navigated by the android to the menu. What I want to do is to preserve the correct navigation experience of the user, and when I'm pressing the back button it will take me to activity number 2, and when I'm pressing there on the back button, it will take me to activity number 1, and so on.
Another problem I have is that, when I'm opening activity number 2, I need to set there some extra data in the intent, but I don't know how to set it.
Summery of my problem: preserve the correct navigation of the user and set some extras for the activity that will be open by the back button click.

Here is my notification code:

NotificationCompat.Builder mBuilder =
                new NotificationCompat.Builder(this)
                .setSmallIcon(R.drawable.ic_launcher)
                .setContentTitle("New Question")
                .setContentText("" + CurrentQuestion.getAuthor().getUserName() + ": " + CurrentQuestion.getQuestion() + "");

        Intent openHomePageActivity = new Intent("com.example.ihelp.HOMEPAGEACTIVITY");
        TaskStackBuilder stackBuilder = TaskStackBuilder.create(this);
        stackBuilder.addNextIntent(openHomePageActivity);
        PendingIntent resultPendingIntent =
                stackBuilder.getPendingIntent(
                    0,
                    PendingIntent.FLAG_UPDATE_CURRENT
                );
        mBuilder.setContentIntent(resultPendingIntent);
        NotificationManager mNotificationManager =
            (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
        mNotificationManager.notify(0, mBuilder.build());

Thanks!

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Looks like you want to synthesize a back stack: http://developer.android.com/training/implementing-navigation/temporal.html#SynthesizeBackStack (see "Create back stack when starting the activity")

and also http://developer.android.com/guide/topics/ui/notifiers/notifications.html#NotificationResponse ("Preserving Navigation when Starting an Activity" as a "Regular activity")


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

57.0k users

...