android– 单击通知时恢复活动

android– 单击通知时恢复活动,第1张

概述我已经创建了一个管理短信的应用程序,我已经创建了通知,但是当我点击它们时它启动了另一个活动,我想知道如何检查一个活动是否已经停止并恢复它.以下是用于创建pendingintent的代码:privatevoidcreateNotification(SmsMessagesms,Contextcontext){finalNotificationM

我已经创建了一个管理短信的应用程序,我已经创建了通知,但是当我点击它们时它启动了另一个活动,我想知道如何检查一个活动是否已经停止并恢复它.

以下是用于创建pendingintent的代码:

private voID createNotification(SmsMessage sms, Context context){    final notificationmanager nm = (notificationmanager)context.getSystemService(Context.NOTIFICATION_SERVICE);    String contentTitle = "";    // construct the Notification object.        final NotificationCompat.Builder  builder = new NotificationCompat.Builder(context)        .setContentTitle(contentTitle)         .setContentText(sms.getMessageBody())         .setSmallicon(R.drawable.ic_launcher)         .setLargeIcon(getIconBitmap())         .setNumber(nmessages);        builder.setautoCancel(true);        //(R.drawable.stat_sample, tickerText,          //      System.currentTimeMillis());        // Set the info for the vIEws that show in the notification panel.        //notif.setLatestEventInfo(this, from, message, contentIntent);        /*        // On tablets, the ticker shows the sender, the first line of the message,        // the photo of the person and the app icon.  For our sample, we just show        // the same icon twice.  If there is no sender, just pass an array of 1 Bitmap.        notif.tickerTitle = from;        notif.tickerSubTitle = message;        notif.tickerIcons = new Bitmap[2];        notif.tickerIcons[0] = getIconBitmap();;        notif.tickerIcons[1] = getIconBitmap();;        */     // Creates an explicit intent for an Activity in your app        Intent resultIntent = new Intent(context, BasicActivity.class);        resultIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_top | Intent.FLAG_ACTIVITY_SINGLE_top);        // Because clicking the notification opens a new ("special") activity, there's        // no need to create an artificial back stack.        PendingIntent resultPendingIntent =            PendingIntent.getActivity(            context,            0,            resultIntent,            PendingIntent.FLAG_UPDATE_CURRENT        );       // Ritardo in millisecondi     builder.setContentIntent(resultPendingIntent);     nm.notify(R.drawable.ic_drawer, builder.build());

解决方法:

你需要在你的PendingIntent中设置标志……就像FLAG_UPDATE_CURRENT一样.

这就是全部.
http://developer.android.com/reference/android/app/PendingIntent.html

编辑1:我误解了这个问题.

以下是具有相同问题但已解决的主题的链接:

resuming an activity from a notification

Notification Resume Activity

Intent to resume a previously paused activity (Called from a Notification)

Android: resume app from previous position

请阅读上述答案以获得完整的解决方案,并告诉我它是否有效.

总结

以上是内存溢出为你收集整理的android – 单击通知时恢复活动全部内容,希望文章能够帮你解决android – 单击通知时恢复活动所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/web/1101128.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-05-28
下一篇2022-05-28

发表评论

登录后才能评论

评论列表(0条)

    保存