相关疑难解决方法(0)

onNewIntent()生命周期和已注册的侦听器

我正在使用singleTop Activity来通过搜索对话框接收意图onNewIntent().

我注意到的是onPause()之前调用过onNewIntent(),然后调用它onResume().视觉:

  • 搜索对话框已启动
  • 搜索意图触发了活动
  • onPause()
  • onNewIntent()
  • onResume()

问题是我有注册的监听器onResume()被删除onPause(),但在onNewIntent()通话中需要它们.有没有一种标准方法可以让这些听众可用?

lifecycle android android-intent

140
推荐指数
2
解决办法
9万
查看次数

片段在方向更改时恢复状态

我必须在我的应用程序中实现"标准"片段导航(请参阅链接).

问题是当设备处于纵向模式时,应该只显示1个片段,当它旋转到横向模式时,应显示2个片段.

我试着用两种不同的方式做到这一点:

1)我只使用一个具有不同肖像和横向布局的活动.

纵向布局xml:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >

    <FrameLayout
        android:id="@+id/main_frame_fragment_container"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />

</RelativeLayout>
Run Code Online (Sandbox Code Playgroud)

这里的景观布局:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:baselineAligned="false"
    android:orientation="horizontal" >

    <FrameLayout
        android:id="@+id/main_frame_fragment_container_left"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_weight="1" />

    <FrameLayout
        android:id="@+id/main_frame_fragment_container_right"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_weight="1" />

</LinearLayout>
Run Code Online (Sandbox Code Playgroud)

Activity`s onCreate方法:

    private static ItemsFragment mItemsFragment;
    private static ItemDetailsFragment mItemDetailsFragment;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        if (mItemsFragment == null) {
            mItemsFragment = ItemsFragment.newInstance();
        }
        if (mItemDetailsFragment == null) {
            mItemDetailsFragment = ItemDetailsFragment.newInstance();
        }

        if (isLandscape()) { …
Run Code Online (Sandbox Code Playgroud)

android screen-orientation android-fragments android-fragmentactivity onrestoreinstancestate

11
推荐指数
1
解决办法
2万
查看次数

如何控制Android后台堆栈

可以说我有

A-> B-> C-> D->电子

在android后台堆栈中.我希望能够回到以下之一:

A->B->C
A->B
A
Run Code Online (Sandbox Code Playgroud)

我怎样才能做到这一点?希望不会强制返回按钮点击.

stack android back activity-stack android-activity

5
推荐指数
2
解决办法
3万
查看次数

屏幕方向更改时如何开始新活动?Android的

我正在编写一个应用程序,在纵向视图中顶部有一个图库,当您单击图片时,它将膨胀并填满整个屏幕.

这适用于横向模式,画廊覆盖了大部分图片,一般看起来很糟糕.

我为横向模式制作了一个GridView.我现在遇到的问题是当方向发生变化时,将其从图库活动更改为Gridview活动.有任何想法吗?

android landscape orientation android-activity

0
推荐指数
1
解决办法
1903
查看次数