2013-07-31 113 views
3

我有一个音乐播放器活动,其行为不符合我的要求。此活动可以从应用程序内部,通知栏以及从后台切换/恢复应用程序打开。从活动而不是家长返回到主屏幕

当它从应用程序启动 - > backPress活动 - >返回到以前的应用程序活动。 OK

当从通知发布 - > backPress上的活动 - >返回到主屏幕(这是确定)

When resumed from homeScreen/recent apps -> backPress on activity -> returns to home screen (not OK) - 用户承担,回到应用程序,因为这个活动是叶和标签活动根活动。

我想回到父活动时按回来,而不是在主屏幕上(当从通知恢复,这是确定的,如果返回到主屏幕,但在这种情况下两种变种都适合我)

<activity android:name=".player.PlayerActivity" 
        android:configChanges="keyboardHidden|orientation" 
        android:label="@string/audio_player_activity_title" 
        android:launchMode="singleInstance"/> 

和启动活动:

//this intent is started from a fragment (SherlockFragment) 
Intent i = new Intent(getActivity(), PlayerActivity.class); 
startActivity(i); 

注: 我想单一实例,以避免在屏幕上运行相同类型的2个活动(使用通知时发生)

有人可以帮助我吗?

回答

2

当您使用launchMode:“singleInstance”时,您的活动将在新任务中启动: [http://developer.android.com/guide/topics/manifest/activity-element.html] [1 ] 这就是为什么你没有看到背堆栈的正常行为。 要确保机器人instanciates一旦你的活动,你可以设置标志:FLAG_ACTIVITY_REORDER_TO_FRONT当您启动活动

intent.setFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT); 
+0

它现在。谢谢 –