开发者

onActivityResult for PendingIntent

How do i get the result of an activity started from NotificationManager?

In other words i need to get the resultCode from a PendingIntent.

public void test(Context context){
 开发者_Python百科   Notification notification = new Notification(null, "text", System.currentTimeMillis());
    Intent intent = new Intent(Intent.ACTION_VIEW);
    intent.setData(Uri.parse("http://www.example.com"));
    PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, intent, 0);
    notification.setLatestEventInfo(context, "text", "text", pendingIntent);
    notificationManager.notify(0, notification);
}

I want to be notified when the browser's activity ends.

OBS: This code is outside an activity, that's why it recieves the context as parameter


Let's assume you have activity A that sets PendingIntent. This PendingIntent calls activity B. You want receive result of B.

You can do this by introducing proxy activity: A -> PendingIntent -> ProxyActivity --> startActivityForResult --> B. This way you'll receive result from B into your ProxyActivity activity.

Note that you should call startActivityForResult() in ProxyActivity.onCreate().


Let's see in simply way , IN Activity A :

intet.putStringExtra("from notification") ;

In Activity B:

if (getintent().getStringExtra("from notification") !=null ){
//TODO do what u want !
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜