android - using pending intent to start activity

2019-09-07 20:18发布

问题:

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 ?