Android的:如何从一个通知简历的应用程序? [英] Android: How to resume an App from a Notification?

查看:102
本文介绍了Android的:如何从一个通知简历的应用程序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想我编程通知恢复我的应用程序,而不是简单地开始我的应用程序的新实例......我基本上找它做同样的事情时,Home键是长期pressed和应用程序是从那里重新开始。

I am trying to program my notification to RESUME my app, instead of simply starting a new instance of my app... I am basically looking for it to do the same thing as when the Home button is long-pressed and the app is resumed from there.

下面是我目前做的:

void notifyme(String string){

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

    int icon = R.drawable.notification_icon;        // icon from resources
    CharSequence tickerText = string + " Program Running...";     // ticker-text
    long when = System.currentTimeMillis();         // notification time
    Context context = getApplicationContext();      // application Context
    CharSequence contentTitle = *********;  // expanded message title
    CharSequence contentText = string + " Program Running...";//expanded msg text

    Intent notificationIntent = new Intent(this, Main.class);
    PendingIntent contentIntent = PendingIntent.getActivity(
                                                this, 0, notificationIntent, 0);

    // the next two lines initialize the Notification, using the configurations
    // above
    Notification notification = new Notification(icon, tickerText, when);
    notification.setLatestEventInfo(context, contentTitle, contentText,
                                                                contentIntent);
    final int HELLO_ID = 1;
    mNotificationManager.notify(HELLO_ID, notification);
}

我猜测,新的原意是问题所在......任何帮助,将AP preciated!

I am guessing that the new Intent line is where the problem lies... any help would be appreciated!

推荐答案

您需要设置标志

 notification.flags = Notification.FLAG_ONGOING_EVENT | Notification.FLAG_NO_CLEAR;   
 notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);

另外,如果你从来没有希望这是一个重复的活动给它这个属性在清单

Also, if you never ever want there to be a duplicate activity give it this attribute in the manifest

android:launchMode="singleTask"

这篇关于Android的:如何从一个通知简历的应用程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆