如何获得PendingIntent.getActivity的结果 [英] How to get a result of PendingIntent.getActivity

查看:665
本文介绍了如何获得PendingIntent.getActivity的结果的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用挂起的意图发动闹钟(使用AlarmManager)。我需要不同的结果$ C $的推出活动c根据其中的2个按钮放置在它的用户点击(贪睡或取消)之一。我如何得到这样的结果?不幸的是,该方法onActivityResult()在父活性不发射后完成()方法在封闭的​​活动展开。在Android的文件,它规定

I am using a pending intent to launch an alarm clock (using AlarmManager). I need different result code of the launched activity based on which one of the 2 buttons placed in it the user clicks (Snooze or Cancel). How do I get this result? Unfortunately, the method onActivityResult() is not launched in the parent activity after finish() method is launched on the closing activity. In the Android documentation, it states

PendingIntent.getActivity:   检索PendingIntent,将开始一个新的活动,比如调用Context.startActivity(意图)

"PendingIntent.getActivity: Retrieve a PendingIntent that will start a new activity, like calling Context.startActivity(Intent)"

我会需要像Context.startActivityForResult(意向),但对未决意图。

I would need something like Context.startActivityForResult(Intent) but for Pending Intent.

推荐答案

PendingIntents的设计,他们可以从其他应用程序启动,也就是说,它是不明确谁应该得到的结果。这就是为什么startActivityForResult()是没有意义的PendingIntent。我的建议是当你完成了previously启动的活动,以发送广播消息

PendingIntents are designed that they can be launched from other applications, i.e. it isn't clear who should receive the result. That's why startActivityForResult() is meaningless for PendingIntent. My suggestion is to send a broadcast message when you finish the previously launched activity

@Override
public void onFinish() {
    super.onFinish();
    Intent intent = new Intent(YOUR_CUSTOM_ACTION);
    // Put data to intent
    sendBroadcast(intent);
}

和接收使用的结果在其他活动 BroadcastReceiver的

And receive the result in other activity using BroadcastReceiver:

public class ActivityResultReceiver extends BroadcastReceiver{

    @Override
    public void onReceive(Context context, Intent intent) {
        // Retrieve data from intent
    }

}

这篇关于如何获得PendingIntent.getActivity的结果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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