简体   繁体   中英

Resuming Android app from Notification

How do I resume an Android app from Notification? 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. It's propably not the most graceous way, but it works nonetheless

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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