android - using pending intent to start activity

限于喜欢 提交于 2019-12-25 02:29:45

问题


I have 2 apps App1 and App2. I need to test sending a pending intent from App1 to App2 that allows App2 to start an activity in App1.

In App1 (Main Activity):

Intent i = new Intent();
i.setClassName("com.android.testapp1.app", "Activity2");
PendingIntent pit = PendingIntent.getActivity(getApplicationContext(), 1, i, 0);
Intent intent= new Intent();
intent.setAction("com.android.testapp2.app.activity2_action");
intent.putExtra("pi", pit);

startActivity(intent);

In App2's Activity2 :

Intent i = getIntent();
PendingIntent pi = i.getParcelableExtra("pi");
pi.send();

This doesn't launch App1's Activity2. What am I missing in this use of pending intent ? Am I using pending intent the wrong way ?

来源:https://stackoverflow.com/questions/24346423/android-using-pending-intent-to-start-activity

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!