如何唤醒已经在Android C2DM消息后,正在运行的应用 [英] how to awake already running app after c2dm message on android

查看:179
本文介绍了如何唤醒已经在Android C2DM消息后,正在运行的应用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法醒来已经C2DM消息后,从通知栏上运行的应用程序?
我有这个应用程序,与接收来自我的服务器推送通知做一些处理C2DM服务器注册。所以以后我从服务器接收C2DM的消息,它显示在状态栏通知用户,用户扩展了我的应用程序的通知和点击,带来了它。

一切都很好,但如果这个程序已经运行前(从图标盯着),这将载入我的应用程序的另一个实例到内存中。还有些东西崩溃在里面。我已经改变了的android:我的所有活动launchMode =singleTop,我尝试使用 intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP)在我的通知,没有运气。我总是最后2应用程序运行。

任何帮助pciated AP $ P $

我在这里,我使用后,我收到C2DM消息来创建通知静态函数:

 公共静态无效notifyStart(上下文的背景下,字符串notificationText){
        //通知
        字符串NS = Context.NOTIFICATION_SERVICE;
        NotificationManager mNotificationManager =(NotificationManager)context.getSystemService(NS);        INT图标= R.drawable.icon_notify;
        CharSequence的tickerText = notificationText;
        时长= System.currentTimeMillis的();        通知通知=新的通知(图标,tickerText时);
        notification.ledARGB = 0xff00ff00;
        notification.ledOnMS = 400;
        notification.ledOffMS = 400;
        notification.flags | = Notification.FLAG_SHOW_LIGHTS;
        notification.defaults | = Notification.DEFAULT_SOUND;        CharSequence的contentTitle =应用程序名称;
        CharSequence的contentText = notificationText;        意图notificationIntent =新意图(背景下,home.class);
        notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);        的PendingIntent contentIntent = PendingIntent.getActivity(上下文,0,notificationIntent,0);        notification.setLatestEventInfo(背景下,contentTitle,contentText,contentIntent);        mNotificationManager.notify(1350,通知);
    }

和这里是我的家活动:

 <活动机器人:家的名字=
              机器人:标签=@字符串/ APP_NAME
              机器人:主题=@安卓风格/ Theme.NoTitleBar
              机器人:launchMode =singleTop>
        &所述;意图滤光器>
            <作用机器人:名字=android.intent.action.MAIN/>
            <类机器人:名字=android.intent.category.LAUNCHER/>
        &所述; /意图滤光器>
    < /活性GT;


解决方案

大家好,我感到非常抱歉,但它是我的错:|前两天我决定改变包装我的应用程序的名字,忘了从手机中删除旧的应用程序。我不知道这会导致我的手机在两个独立的安装,任务管理器只显示应用程序的名称,以便它没有看起来像有相同的应用程序的两个实例,其实有各自的一个实例;)烦恼遗憾和AP preciate您愿意帮助:)

is there a way to awake already running app from the notification bar after c2dm message? i have this app that is registered with c2dm servers that receives push notifications from my server to do some processing. so after i receive c2dm message from my server, it displays the status bar notification to the user, user expands the notifications and clicks on my app, brings it up.

all is good but if this app was already running before (stared from the icon) this would load another instance of my app into memory. also some of the things are crashing in it. i already changed the android:launchMode="singleTop" on all my activities, i tried using intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP) in my notification and no luck. i always end up with 2 apps running.

any help is appreciated

here my static function that i use to create a notification after i receive the c2dm message:

public static void notifyStart(Context context, String notificationText) {      
        //notification
        String ns = Context.NOTIFICATION_SERVICE;
        NotificationManager mNotificationManager = (NotificationManager) context.getSystemService(ns);

        int icon = R.drawable.icon_notify;
        CharSequence tickerText = notificationText;
        long when = System.currentTimeMillis();

        Notification notification = new Notification(icon, tickerText, when);              
        notification.ledARGB = 0xff00ff00;
        notification.ledOnMS = 400;
        notification.ledOffMS = 400;
        notification.flags |= Notification.FLAG_SHOW_LIGHTS;        
        notification.defaults |= Notification.DEFAULT_SOUND;   

        CharSequence contentTitle = "App Name";
        CharSequence contentText = notificationText;

        Intent notificationIntent = new Intent(context, home.class);
        notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);

        PendingIntent contentIntent = PendingIntent.getActivity(context, 0, notificationIntent, 0);

        notification.setLatestEventInfo(context, contentTitle, contentText, contentIntent);   

        mNotificationManager.notify(1350, notification);          
    }

and here is my home activity:

    <activity android:name=".home"
              android:label="@string/app_name"
              android:theme="@android:style/Theme.NoTitleBar"
              android:launchMode="singleTop" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>

解决方案

guys, i am very sorry but it was my fault :| couple of days ago i decided to change the name of the package of my app and forgot to remove the old app from the phone. i didn't realize that it would cause two separate installations on my phone, the task manager displays only app name so it did look like there were two instances of the same app, in fact there was one instance of each ;) sorry about trouble and appreciate your willingness to help :)

这篇关于如何唤醒已经在Android C2DM消息后,正在运行的应用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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