English 中文(简体)
在进行筛查后,采用“观察”套管套套套数吗?
原标题:Using ViewPager caches Fragments after screen rotation?

I initially create my fragments inside the Activity onCreate(). Than I go about creating the ViewPager and setting up the adapter. I keep a global reference to the fragments so I can update them as needed. Also, these fragments are accessed by the adapter.

我的问题是,一旦屏幕重新布置碎片,我就会注意到,“观点”仍然含有最初制造的碎片......?

我应如何处理我碎片的生命周期? 我需要能够直截了该活动的碎块。 是否有一只一带一片一片好的想法? 或者仅仅是一个记忆泄露者?

protected void onCreate (Bundle savedInstanceState)
{
...
...
        // set up cards
        mFrag1 = new Frag1();
        mFrag1.setOnActionEventListener(mOnActionEvents);

        mFrag2 = new Frag2();
        mFrag3 = new Frag3();

        mFragPager = (ViewPager) findViewById(R.id.vpPager);
        mFragAdapter = new FragAdapter(getSupportFragmentManager());
        mFragPager.setAdapter(mCardAdapter);
        mFragPager.setOnPageChangeListener(mOnCardChange);
}
最佳回答

全球事件和静态碎片无疑是一个坏的想法。 除非在碎块上打上setRetainInstance(),否则,在母体活动重新分类(在屏幕上轮流等)时,该编码将重新编号。 当然,这将产生新的零碎事例,你的旧提法将是无效的。 你们应该根据需要,通过<条码>FragmentManager.findFragmentById/Tag(,当然不将这些碎片储存在固定变量中。

或许需要显示我们守则的更多内容,但只要你在<条码>onCreate()中制造碎片,这些参考文献在活动期间就应当有效。 核对图书馆的相容性样本代码,以便更多使用带的碎块。 ViewPager

问题回答

暂无回答




相关问题
Android - ListView fling gesture triggers context menu

I m relatively new to Android development. I m developing an app with a ListView. I ve followed the info in #1338475 and have my app recognizing the fling gesture, but after the gesture is complete, ...

AsyncTask and error handling on Android

I m converting my code from using Handler to AsyncTask. The latter is great at what it does - asynchronous updates and handling of results in the main UI thread. What s unclear to me is how to handle ...

Android intent filter for a particular file extension?

I want to be able to download a file with a particular extension from the net, and have it passed to my application to deal with it, but I haven t been able to figure out the intent filter. The ...

Android & Web: What is the equivalent style for the web?

I am quite impressed by the workflow I follow when developing Android applications: Define a layout in an xml file and then write all the code in a code-behind style. Is there an equivalent style for ...

TiledLayer equivalent in Android [duplicate]

To draw landscapes, backgrounds with patterns etc, we used TiledLayer in J2ME. Is there an android counterpart for that. Does android provide an option to set such tiled patterns in the layout XML?

Using Repo with Msysgit

When following the Android Open Source Project instructions on installing repo for use with Git, after running the repo init command, I run into this error: /c/Users/Andrew Rabon/bin/repo: line ...

Android "single top" launch mode and onNewIntent method

I read in the Android documentation that by setting my Activity s launchMode property to singleTop OR by adding the FLAG_ACTIVITY_SINGLE_TOP flag to my Intent, that calling startActivity(intent) would ...

From Web Development to Android Development

I have pretty good skills in PHP , Mysql and Javascript for a junior developer. If I wanted to try my hand as Android Development do you think I might find it tough ? Also what new languages would I ...

热门标签