【问题标题】:Returning to home screen from Activity instead of parent从 Activity 而不是父级返回主屏幕
【发布时间】:2013-07-31 23:04:33
【问题描述】:

我的音乐播放器活动不符合我的要求。可以从应用程序内部、通知栏以及从后台切换/恢复应用程序时打开此活动。

当它从应用程序启动时 -> backPress on activity -> 返回上一个应用程序活动。好的

当从通知启动时 -> backPress on activity -> 返回主屏幕(没关系)

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 个相同类型的活动(使用通知时发生)

有人可以帮我解决这个问题吗?

【问题讨论】:

    标签: android android-intent android-activity


    【解决方案1】:

    当您使用 launchMode: "singleInstance" 时,您的活动将在一个新任务中启动: [http://developer.android.com/guide/topics/manifest/activity-element.html][1] 这就是为什么你看不到回栈的正常行为。 为确保 android 在您的活动时实例化,您可以在启动活动时设置标志:FLAG_ACTIVITY_REORDER_TO_FRONT

    intent.setFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-08-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-03-25
      • 1970-01-01
      • 2012-03-28
      • 2019-05-24
      相关资源
      最近更新 更多