收到通知后,我要退出并返回主屏幕吗? [英] After notification, I would like to exit and go back to main screen?

查看:104
本文介绍了收到通知后,我要退出并返回主屏幕吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在第一次测试android通知.我在一个包含联系人列表的页面上,然后单击一个以触发我的通知.通知将我带到带有这些按钮的页面上

I am testing out android notifications for the first time. I am on a page with a list of contacts and I click one to trigger my notification. The notification lands me on a page with these buttons

  • 快速文字

我单击打oo睡",然后单击"10分钟"按钮,此时,我打电话给

I click snooze, then I click 10 minutes button and at this point, I call

    finish();
    System.exit(0);

我在这篇文章中找到的

https://stackoverflow.com/questions/6014028/closing-application-with-exit-button

但是,该应用程序不会退出,而是会再次返回贪睡和快速文本选项,这非常令人困惑.

However, the app does not exit but rather goes back to the snooze and quick text options again which is very very confusing.

我如何直接退出应用程序,或者如果用户正在使用该应用程序,请返回到提名开始之前打开的页面? (即,用户最好回到我认为包含联系人列表的页面上)

How do I just exit the app OR IF the user is in process of using the app, go back to the page that was open before the nofication came in? (ie. it would be preferable for the user to land back on the page with the list of contacts I think)

我不确定是否相关,因为我不知道哪些信息很重要,但这是用户单击联系人时的触发通知代码

I am not sure it is relevant as I don't know what info is important but this is my firing notification code when user clicks a contact

private void displayNotifiation(Contact contact, byte[] img) {
    int notificationId = contact.hashCode();

    Bitmap bitmap = BitmapFactory.decodeByteArray(img, 0, img.length);

    // Create an explicit intent for an Activity in your app
    Intent intent = new Intent(mContext, ActivityNotificationLanding.class);
    Uri uri = Uri.parse("http://notexist.mykeepintouch.app/contactid/"+contact.getId());
    intent.setData(uri);
    intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
    gson.putExtra(intent, IntentFlashStore.CONTACT_KEY, contact);
    intent.putExtra(NOTIFICATION_ID, notificationId);
    PendingIntent pendingIntent = PendingIntent.getActivity(mContext, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);

    Log.d(TAG, "onClick: put info="+contact.getName()+" notifId:"+notificationId);


    NotificationCompat.Builder builder = new NotificationCompat.Builder(mContext, MainActivity.CHANNEL_ID)
            .setSmallIcon(R.drawable.plus_icon5)
            .setContentTitle("It's time to reach out to "+contact.getName())
            .setContentText("For your health")
            .setPriority(NotificationCompat.PRIORITY_DEFAULT)
            .setLargeIcon(bitmap)
            .setContentIntent(pendingIntent)
            .setAutoCancel(false);

    NotificationManagerCompat notificationManager = NotificationManagerCompat.from(mContext);

    // notificationId is a unique int for each notification that you must define
    notificationManager.notify(notificationId, builder.build());
}

推荐答案

您可以更改

intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);

intent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);

当您单击按钮时,仅调用finish()

when you click button only call finish()

这篇关于收到通知后,我要退出并返回主屏幕吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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