简体   繁体   English

从通知中恢复Android应用

[英]Resuming Android app from Notification

How do I resume an Android app from Notification? 如何从通知中恢复Android应用程序? I want to be able to resume the instance from where it left, with all bounded Services, and settings etc. Instead of a complete new instance. 我希望能够使用所有有限的服务和设置等从它离开的位置恢复该实例。而不是一个完整的新实例。 This is my code: 这是我的代码:

String ns = Context.NOTIFICATION_SERVICE;
        mNotificationManager = (NotificationManager)
                                                    getSystemService(ns);

        Intent notificationIntent = new Intent(this, MeasurementsStarter.class);
        PendingIntent contentIntent = PendingIntent.getActivity(
                                                    this, 0, notificationIntent, 0);
        // the next two lines initialize the Notification, using the configurations
        // above
        notification = new Notification(R.drawable.ic_launcher, "Metingen draaien",System.currentTimeMillis());
        notification.setLatestEventInfo(getBaseContext(), "Metingen ManDown", "Metingen Mandown draaien nog",
                                                                    contentIntent);
        notification.flags = Notification.FLAG_ONGOING_EVENT | Notification.FLAG_NO_CLEAR;   
        notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
        final int HELLO_ID = 1;
        mNotificationManager.notify(HELLO_ID, notification);

I kind of found an answer, I manually set the data from all of my textFields etc. and just put my bindService in my onCreate() method. 我有点找到答案了,我手动设置了所有textFields等中的数据,然后将我的bindService放在了onCreate()方法中。 It's propably not the most graceous way, but it works nonetheless 这可能不是最优雅的方式,但是仍然可以

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM