在我有两个活动的应用程序中,活动 A 有一个按钮,活动 B 有音频播放器,带有通知内容和 HOME 选项菜单。
- 启动活动 A。单击按钮 -> 开始活动 B
- 在活动 B 中 - 开始播放器并发出通知。
- 单击设备返回按钮
- Activity B 销毁并单击设备返回按钮
- 活动 A 销毁
- 点击通知 -> 转到活动 B
- 在活动 B 单击 HOME 选项菜单 -> 开始活动 A
- 单击按钮 - 不工作
任何想法?
Intent i = new Intent(getBaseContext(),ActivityB);
i.putExtra("NotifID", NOTIFICATION_ID);
i.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
pi = PendingIntent.getActivity(getBaseContext() , 0, i,PendingIntent.FLAG_UPDATE_CURRENT);
contentView = new RemoteViews(getPackageName(), R.layout.my_notification);
bitmap = ((BitmapDrawable)drawable).getBitmap();
contentView.setImageViewBitmap(R.id.imageNotify, bitmap);
contentView.setTextViewText(R.id.titleNotify, text);
contentView.setTextViewText(R.id.textSong, singer);
mNotification.contentView = contentView;
mNotification.contentIntent = pi;
mNotification.tickerText = text;
mNotification.icon = R.drawable.icon;
mNotification.flags |= Notification.FLAG_ONGOING_EVENT;
mNotificationManager.notify(NOTIFICATION_ID, mNotification);
活动A,
playButton = ((Button)findViewById(R.id.nowplaying));
playButton.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
Intent intent = new Intent(getBaseContext(),ActivityB.class);
intent.putExtra("isFromList", false);
startActivity(intent);
}
});
在活动 B 中,
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case R.id.home:
Intent myIntent = new Intent(this, ActivityA.class);
startActivity(myIntent);
break;
并用于上述通知。
显现
<activity
android:name="com.android.ActivityA"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:configChanges="orientation|keyboardHidden"
android:label="@string/app_name"
android:screenOrientation="portrait" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name="com.android.ActivityB"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:configChanges="orientation|keyboardHidden"
android:screenOrientation="portrait" >
</activity>