在我的应用程序中有两个活动,在活动A中有一个按钮,活动B有音频播放器,其中包含通知内容和HOME选项菜单。
有什么想法吗?
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);
}
});
在Acitvity 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>
答案 0 :(得分:0)
我假设当用户从ActivityB选择“HOME菜单选项”以启动ActivityA时,你想“返回ActivityA”。在这种情况下,您需要在启动ActivityA后在finish()
中添加对onOptionsItemSelected()
的调用。
我已经要求您将您的清单条目发布到ActivityA和ActivityB,这可能会更清楚地解决问题。