方向更改后 ActionbarSherlock 进度不可见

发布于 2024-12-29 14:59:28 字数 5185 浏览 2 评论 0原文

在 2.x 物理和虚拟设备上进行了测试。未在 v3 上测试>

当应用程序启动时,无论是纵向还是横向模式,进度条都会显示在操作栏中。 FragmentActivity 在方向更改后重新启动后,进度不再显示是从下面的 onCreate 代码调用(我检查了加载程序正在运行,并且代码步骤将进度条设置为 Boolean.TRUE),还是从简单的按钮单击事件调用setProgressBarInminatedVisibility(Boolean.TRUE);

onSaveInstanceState -> onCreate 方法在方向更改时执行,因此 FragmentActivity 正在停止/启动。

我检查了参考文献以确保我使用的是 android.support.v4.view。 还使用带有选项卡/片段的 ViewPagerIndicator - 不应该有任何轴承。

在方向更改/FragmentActivity 重新启动后,由片段添加到操作栏的刷新按钮显示正常。


实际上...我刚刚注意到在方向更改后查看 logcat 调试时出现了一些奇怪的情况。 FragmentActivity 似乎开始两次查看写入日志的行,再次调用 onSaveInstanceState,然后再调用另一个 onCreate ???

01-28 10:25:45.446: D/DonorDetailsContainerFragmentActivity(4728): onCreate

01-28 10:26:02.457: D/DonorDetailsContainerFragmentActivity(4728): loaderHasStarted

01-28 10:26:02.457: D/DonorDetailsContainerFragmentActivity(4728): onCreateLoader 0

01-28 10:26:04.437: D/DonorDetailsContainerFragmentActivity(4728): onLoadFinished 0

01-28 10:26:04.447: D/DonorDetailsContainerFragmentActivity(4728): loaderHasFinished

**Flip to landscape here**

01-28 10:29:07.567: D/DonorDetailsContainerFragmentActivity(4728): onSaveInstanceState

01-28 10:29:08.197: D/DonorDetailsContainerFragmentActivity(4728): onCreate

01-28 10:29:08.427: D/DonorDetailsContainerFragmentActivity(4728): loaderHasStarted

01-28 10:29:08.427: D/DonorDetailsContainerFragmentActivity(4728): onCreateLoader 0

**Nothing happened here - I only changed orientation once**

01-28 10:29:08.458: D/DonorDetailsContainerFragmentActivity(4728): onSaveInstanceState

01-28 10:29:08.686: D/DonorDetailsContainerFragmentActivity(4728): onCreate

01-28 10:29:17.236: D/DonorDetailsContainerFragmentActivity(4728): onLoadFinished 0

01-28 10:29:17.236: D/DonorDetailsContainerFragmentActivity(4728): loaderHasFinished

    public class DonorDetailsContainerFragmentActivity extends FragmentActivity
            implements OnLoaderListener,
            LoaderManager.LoaderCallbacks<LoaderStatus> {



        @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        // This has to be called before setContentView and you must use the
        // class in android.support.v4.view and NOT android.view
        requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);

        setContentView(R.layout.main);

        Log.d(LOG_TAG, "onCreate");

        mAdapter = new ViewPagerTitleAdapter(getSupportFragmentManager());

        mPager = (ViewPager) findViewById(R.id.pager);
        mPager.setAdapter(mAdapter);

        TabPageIndicator indicator = (TabPageIndicator) findViewById(R.id.tabindicator);
        indicator.setViewPager(mPager);


        // first check if we already have a running loader
        if ((savedInstanceState != null)
                && savedInstanceState.containsKey("RUNNING_LOADERS")) { 
            mRunningLoaders = savedInstanceState.getParcelable("RUNNING_LOADERS");
        }

        if (mRunningLoaders == null) {
            mRunningLoaders = new RunningLoadersList(); 
        }


        if (mRunningLoaders != null) {
            for (int i = 0; i < mRunningLoaders.size(); i++) {
                StartLoader(mRunningLoaders.get(i).id,
                        mRunningLoaders.get(i).args);
            }
        }

        if (getSupportLoaderManager().hasRunningLoaders()) {
            setProgressBarIndeterminateVisibility(Boolean.TRUE);
        } else {
            setProgressBarIndeterminateVisibility(Boolean.FALSE);
        }
    }


        @Override
    protected void onSaveInstanceState(Bundle outState) {
        super.onSaveInstanceState(outState);
        outState.putParcelable("RUNNING_LOADERS", mRunningLoaders);

        Log.d(LOG_TAG, "onSaveInstanceState");
    }



Nothing particularly interesting in the manifest.

    <?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.savant.donordetailsviewpagertitle"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk android:minSdkVersion="4" android:targetSdkVersion="13"/>

    <!-- Enable access to the the internet -->
    <uses-permission android:name="android.permission.INTERNET" />

<!-- Enable access to the the network state -->
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />


    <application
        android:name="com.savant.donordetailsviewpagertitle.classes.DonorDetailsViewPagerTitle"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/StyledIndicators">

        <activity android:name=".activities.DonorDetailsContainerFragmentActivity" 
                     android:label="@string/app_name">
            <intent-filter >
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>
</manifest>

Tested on 2.x physical and virtual devices. Not tested on v3>

When the app starts, in either portrait or Landscape mode the progress bar shows in the actionbar fine. After the FragmentActivity restarts following orientation change the progress no longer shows whether called from the onCreate code below (I've checked that the loaders are running and the code steps into setting progress bar to Boolean.TRUE) or from a simple button click event to setProgressBarIndeterminateVisibility(Boolean.TRUE);

The onSaveInstanceState -> onCreate method is executed on orientation change, so the FragmentActivity is being stopped/started.

I've checked the references to make sure I'm using android.support.v4.view.
Also using ViewPagerIndicator with tabs/fragments - which shouldn't have any bearing.

The refresh button added to the actionbar by the fragments appears fine after orientation change/FragmentActivity restart.


Actually... I've just noticed something odd looking at the logcat debugs following an orientation change. The FragmentActivity seems to start twice looking at the lines written to the logs, with onSaveInstanceState being called again followed by another onCreate ???

01-28 10:25:45.446: D/DonorDetailsContainerFragmentActivity(4728): onCreate

01-28 10:26:02.457: D/DonorDetailsContainerFragmentActivity(4728): loaderHasStarted

01-28 10:26:02.457: D/DonorDetailsContainerFragmentActivity(4728): onCreateLoader 0

01-28 10:26:04.437: D/DonorDetailsContainerFragmentActivity(4728): onLoadFinished 0

01-28 10:26:04.447: D/DonorDetailsContainerFragmentActivity(4728): loaderHasFinished

**Flip to landscape here**

01-28 10:29:07.567: D/DonorDetailsContainerFragmentActivity(4728): onSaveInstanceState

01-28 10:29:08.197: D/DonorDetailsContainerFragmentActivity(4728): onCreate

01-28 10:29:08.427: D/DonorDetailsContainerFragmentActivity(4728): loaderHasStarted

01-28 10:29:08.427: D/DonorDetailsContainerFragmentActivity(4728): onCreateLoader 0

**Nothing happened here - I only changed orientation once**

01-28 10:29:08.458: D/DonorDetailsContainerFragmentActivity(4728): onSaveInstanceState

01-28 10:29:08.686: D/DonorDetailsContainerFragmentActivity(4728): onCreate

01-28 10:29:17.236: D/DonorDetailsContainerFragmentActivity(4728): onLoadFinished 0

01-28 10:29:17.236: D/DonorDetailsContainerFragmentActivity(4728): loaderHasFinished

    public class DonorDetailsContainerFragmentActivity extends FragmentActivity
            implements OnLoaderListener,
            LoaderManager.LoaderCallbacks<LoaderStatus> {



        @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        // This has to be called before setContentView and you must use the
        // class in android.support.v4.view and NOT android.view
        requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);

        setContentView(R.layout.main);

        Log.d(LOG_TAG, "onCreate");

        mAdapter = new ViewPagerTitleAdapter(getSupportFragmentManager());

        mPager = (ViewPager) findViewById(R.id.pager);
        mPager.setAdapter(mAdapter);

        TabPageIndicator indicator = (TabPageIndicator) findViewById(R.id.tabindicator);
        indicator.setViewPager(mPager);


        // first check if we already have a running loader
        if ((savedInstanceState != null)
                && savedInstanceState.containsKey("RUNNING_LOADERS")) { 
            mRunningLoaders = savedInstanceState.getParcelable("RUNNING_LOADERS");
        }

        if (mRunningLoaders == null) {
            mRunningLoaders = new RunningLoadersList(); 
        }


        if (mRunningLoaders != null) {
            for (int i = 0; i < mRunningLoaders.size(); i++) {
                StartLoader(mRunningLoaders.get(i).id,
                        mRunningLoaders.get(i).args);
            }
        }

        if (getSupportLoaderManager().hasRunningLoaders()) {
            setProgressBarIndeterminateVisibility(Boolean.TRUE);
        } else {
            setProgressBarIndeterminateVisibility(Boolean.FALSE);
        }
    }


        @Override
    protected void onSaveInstanceState(Bundle outState) {
        super.onSaveInstanceState(outState);
        outState.putParcelable("RUNNING_LOADERS", mRunningLoaders);

        Log.d(LOG_TAG, "onSaveInstanceState");
    }



Nothing particularly interesting in the manifest.

    <?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.savant.donordetailsviewpagertitle"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk android:minSdkVersion="4" android:targetSdkVersion="13"/>

    <!-- Enable access to the the internet -->
    <uses-permission android:name="android.permission.INTERNET" />

<!-- Enable access to the the network state -->
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />


    <application
        android:name="com.savant.donordetailsviewpagertitle.classes.DonorDetailsViewPagerTitle"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/StyledIndicators">

        <activity android:name=".activities.DonorDetailsContainerFragmentActivity" 
                     android:label="@string/app_name">
            <intent-filter >
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>
</manifest>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文