Android - 当我的应用程序完成时恢复后台应用程序

时间:2016-02-10 19:11:56

标签: android android-fragments android-intent android-notifications back-stack

基本上,我正在使用chrome浏览互联网或查看其他应用。我收到一条通知,打开我的申请。我做了一些事情,结束了。我的申请关闭了,我又回到了发射器上。如何让我的应用程序完成并将我返回到我正在浏览的任何以前的app / chrome页面?

此活动的AndroidManifest部分:

<activity
        android:name=".AcceptRejectActivity"
        android:label="@string/title_activity_accept_reject"
        android:screenOrientation="portrait" >
    </activity>

通知代码:

mNotificationManager = (NotificationManager)
            this.getSystemService(Context.NOTIFICATION_SERVICE);
    Intent resultIntent = new Intent(this, AcceptRejectActivity.class);
    resultIntent.putExtra("message","Do you choose to accept this message?");      

    TaskStackBuilder stackBuilder = TaskStackBuilder.create(this);
    stackBuilder.addParentStack(AcceptRejectActivity.class);

    // Adds the Intent that starts the Activity to the top of the stack //
    stackBuilder.addNextIntent(resultIntent);
    PendingIntent contentIntent =
            stackBuilder.getPendingIntent(
                    0,
                    PendingIntent.FLAG_UPDATE_CURRENT
            );
    String msg = "You have a message"
    NotificationCompat.Builder mBuilder =
            new NotificationCompat.Builder(this)
                    .setSmallIcon(R.drawable.ic_logo)
                    .setContentTitle("Message")
                    .setStyle(new NotificationCompat.BigTextStyle()
                            .bigText(msg))
                    .setContentText(msg)
                    .setPriority(Notification.PRIORITY_HIGH);
    mBuilder.setContentIntent(contentIntent);
    mBuilder.setAutoCancel(true);

    android.app.Notification note = mBuilder.build();
    note.defaults |= android.app.Notification.DEFAULT_VIBRATE;
    note.defaults |= android.app.Notification.DEFAULT_SOUND;        

    mNotificationManager.notify(0, note);

片段的关闭功能

private void allDone() {
        Log.i(TAG, "The choice has been made");            
        getActivity().finish();
        //NavUtils.navigateUpFromSameTask(getActivity());
    }

2 个答案:

答案 0 :(得分:0)

这有点奇怪,但是像申请一样,你可以在完成申请后打开浏览器。

String scope = "https://www.googleapis.com/auth/userinfo.email profile";
OAuthService oathService = OAuthServiceFactory.getOAuthService();
User user = oathService.getCurrentUser(scope);

然后您将返回Chrome会话;)。

答案 1 :(得分:0)

我设法解决了我的问题。

Android Manifest:

required="required"

通知代码: 更改了pendingIntent的创建方式。

<activity
        android:name=".AcceptRejectActivity"
        android:label="@string/title_activity_accept_reject"
        android:screenOrientation="portrait"
        android:launchMode="singleInstance"
        android:excludeFromRecents="true">
    </activity>

现在,当我完成处理后,我可以调用finish()或getActivity()。finish(),它会将我带回到您点击通知之前的任何应用程序/浏览器页面。