【问题标题】:How to prevent double-lunching of activity如何防止双餐活动
【发布时间】:2014-04-19 12:02:39
【问题描述】:

我的问题很简单,但我找不到答案。任务是从通知中午餐活动,但如果活动正在工作,只需将数据传递给该活动。我的应用只是一个接一个的午餐活动,不适合我。

        Intent notificationIntent = new Intent(this, com.inyourcells.finelife.MainDesk.class);
        notificationIntent.putExtra(MainDesk.CONFIRM_INDEX_PARAM, confirmIndex);
        pIntent = PendingIntent.getActivity(this, id, notificationIntent, PendingIntent.FLAG_UPDATE_CURRENT);


        builder = new Notification.Builder(getApplicationContext())
                .setContentTitle(getString(R.string.new_operation))
                .setContentText(getString(R.string.press_new_operation)+sum+MainDesk.CUR)
                .setTicker(getString(R.string.ticker_new_operation)).setWhen(System.currentTimeMillis())
                .setContentIntent(pIntent)
                .setDefaults(Notification.DEFAULT_SOUND|Notification.DEFAULT_VIBRATE|Notification.DEFAULT_LIGHTS).setAutoCancel(true)
                .setSmallIcon(R.drawable.accounts_icon);
    }

【问题讨论】:

    标签: android android-intent notifications android-pendingintent


    【解决方案1】:

    在清单中为您的 Activity 试试这个:

    android:launchMode="singleTop"
    

    【讨论】:

    • 我正在努力不启动两次,但这种方法不会将意图数据传递给活动。如果活动是午餐,那只是意图不起作用。
    • 我已经创建了onNewIntent()回调函数,我试试。如果没问题,那就是答案
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-03-11
    • 1970-01-01
    • 1970-01-01
    • 2012-01-27
    相关资源
    最近更新 更多