Android带来了当前的活动

时间:2013-02-15 06:30:41

标签: android android-intent android-activity

我在我的应用中收到了有待设置的通知。当我使用我的应用程序时,我会进行多项活动。登录 - >主屏幕 - >关于等我想恢复我的应用程序foregrownd但我不知道哪个是在Intent构造函数中设置它的当前活动。我想从通知中恢复它。如果打开则关闭应用程序,如果关闭则再次打开,因为通知来自服务。

我希望将用户带回来的活动带回来。换句话说,我想模拟行为 - >回到设备的主屏幕[在这个时间应用程序运行但是在后台]并且如果点击应用程序图标..应用程序恢复上一个活动/将它带到前面我点击主页按钮但是也从通知执行此操作

有办法做到这一点吗?

由于

1 个答案:

答案 0 :(得分:0)

            NotificationManager manager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
            Notification notification = new Notification(R.drawable.icon,"Details", System.currentTimeMillis());
            RemoteViews remoteView = new RemoteViews(getPackageName(),R.layout.custom_notification);
            remoteView.setImageViewResource(R.id.icon, R.drawable.icon);
            remoteView.setTextViewText(R.id.Mesg, "Status : "+ details);
            notification.contentView = remoteView;
            Intent notificationIntent = new Intent(context,Form.class).putExtra("layout", "99");
            PendingIntent contentIntent = PendingIntent.getActivity(getApplicationContext(), 0, notificationIntent,Notification.FLAG_AUTO_CANCEL);
            notification.contentIntent = contentIntent;
            notification.flags = Notification.FLAG_AUTO_CANCEL+ Notification.FLAG_ONLY_ALERT_ONCE;
            manager.notify(45, notification);

并在我创建我的应用程序时使用

 Intent i = getIntent();
    k = Integer.parseInt(i.getStringExtra("layout"));
    Log.i(TAG, ">>>>>>>>>>" + k);
    if (k == 99) {
        finish();
    }

这将检查您的活动是否仍然存在。如果活动被杀死或关闭,它将带您进行堆栈顶部的活动。如果应用程序完全关闭,它将不会执行任何操作