Android的通知 - 如何把活动前没有召回活动 [英] Android Notification - How to bring the activity to front without recall the activity

查看:109
本文介绍了Android的通知 - 如何把活动前没有召回活动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的应用程序,在一个活动(AndroidNotification.java)我做了以下内容:

In my app, in an activity(AndroidNotification.java) i am doing the following:

1)我显示一个通知,当用户preSS home键。

1) i am showing a notification when user press home button.

2),当用户单击该通知我展示与活动的应用程序 - AndroidNotification.java

2) when user click the notification i show the app with the activity - AndroidNotification.java

3)我关闭的通知栏上的通知时,我的应用程序来前(​​即在onResume方法)

3) i close the notification on notification bar when my app comes to front(that is in onResume method)

下面code工作,但问题是电话通知的活动(AndroidNotification.java)再次

The below code working but the problem is the notification call the activity(AndroidNotification.java) again

我的问题是我不想要重新启动活动,通知应把

my question is i do not want to relaunch the activity , the notification should bring the

活动的背景前,应该不叫重新开张。

activity to front from background, it should not call relaunch.

目前的行为结果是活动再次呼吁让整机的功能再次奏效。这就是问题所在。

result of the current behavior is activity is called again so that whole functionality is worked again. that is the problem .

我的code:

private NotificationManager mNotificationManager;
Notification notifyDetails;
......
mNotificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
        notifyDetails = new Notification(R.drawable.ic_launcher,
            "Notification, Click Me!", System.currentTimeMillis());

    Context context = AndroidNotification.this;
    CharSequence contentTitle = "Notification Test";
    CharSequence contentText = "Get back to Application on clicking me.";

    Intent notifyIntent = new Intent(context, AndroidNotification.class);
    notifyIntent.setFlags(Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT );

    PendingIntent intent = PendingIntent.getActivity(
            AndroidNotification.this, 0, notifyIntent,0);

    // Set properties to notify object - its title, text
    notifyDetails.setLatestEventInfo(context, contentTitle,contentText, intent);

    // Notify user in status bar
    mNotificationManager.notify(SIMPLE_NOTFICATION_ID, notifyDetails);

是什么,需要添加在AndroidManifest.xml中的特定活动

is anything need to add for the particular activity in AndroidManifest.xml

请帮我。

推荐答案

我已经加入解决了以下在创建方法

i have solved by adding the following in on create method

if ((getIntent().getFlags() & Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT) != 0) { 
    // Activity was brought to front and not created, 
    // Thus finishing this will get us to the last viewed activity 
    finish(); 
    return; 
}

这篇关于Android的通知 - 如何把活动前没有召回活动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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