android-fragmentactivity

Why does the fragment's onCreateView, onCreate, onActivityCreated are called

北慕城南 提交于 2019-11-30 10:23:01
问题 I have an app, that deals with fragments and ViewPager. I have three fragments in a ViewPager. When you switch between them, it always causes the other two fragments to call their's onCreateView methods. How to do it only once, only when FragmentActivity is created??? I've read some questions and tried the solutions, but the fragments still have the same behavior. ListFragment onCreate called twice onCreate() and onCreateView() invokes a lot more than required (Fragments) Here is some code,

Android Fragment - move from one View to another?

岁酱吖の 提交于 2019-11-30 07:31:44
问题 Can i first add a Fragment to a View, then "detach" it, and then "re-attach" it to another View? In code, i want to: fragOne one = new fragOne(); getSupportFragmentManager().beginTransaction() .add(R.id.left, one, "tag").commit(); getSupportFragmentManager().beginTransaction() .detach(one).commit(); // or .remove(), or .addToBackStack(null).remove() getSupportFragmentManager().executePendingTransactions(); getSupportFragmentManager().beginTransaction() .add(R.id.right, one).commit(); But it

Can some draw lifecycle of Fragment and its parent FragmentActivity?

谁都会走 提交于 2019-11-30 05:24:31
In Android docs, I found a specs on Activity lifecycle and on Fragment lifecycle individually, but never together. It does not seem obvious as I attached a debugger to FragmentActivity which hosts my fragment, and the life cycle is more than crazy. It looks like activity finishes first and then fragments starts, which is impossible. Fragment's lifecycle Activity's lifecycle Logically, fragment should "jump into" activity's lifecycle after its onResume and it would end before activity's onPause , but it seems it is not happening. Can someone either show me the lifecycle of the fragment in

Adding PreferenceFragment to FragmentPagerAdapter

女生的网名这么多〃 提交于 2019-11-30 00:03:13
I am trying to add a PreferenceFragment to a FragmentPagerAdapter . My class extends FragmentActivity , I have tried FragmentTransaction , as shown below as well as trying to add to the container and can't seem to get anything to work. No errors are thrown, in fact nothing happens. Main Activity: @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); mSectionsPagerAdapter = new SectionsPagerAdapter(getSupportFragmentManager()); mViewPager = (ViewPager) findViewById(R.id.pager); mViewPager.setAdapter

Can't retain nested fragments

为君一笑 提交于 2019-11-29 23:15:57
Is there another way of saving the state of the nested fragment ? Or if we shouldn't do this, why ? Thanks ! 02-13 11:42:43.258: E/AndroidRuntime(7167): java.lang.IllegalStateException: Can't retain fragements that are nested in other fragments 02-13 11:42:43.258: E/AndroidRuntime(7167): at android.support.v4.app.Fragment.setRetainInstance(Fragment.java:742) You can use FragmentManager.saveFragmentInstanceState(Fragment) to retrieve a fragment state. The return value implements Parcelable, so you can put it in a Bundle. For restoration, you can provide the state after creating the fragment

Using `onRetainCustomNonConfigurationInstance` to retain data across configuration changes

你离开我真会死。 提交于 2019-11-29 22:22:36
I've been programming for Android for some time, and I'm still looking for solutions to retain data over configuration changes. Aside from saving Parcelable s to Activity's Bundle in onSaveInstanceState docs are suggesting using Fragment with setRetainInstance flag set to true. But I've just come across some code that uses onRetainCustomNonConfigurationInstance to hold arbitrary objects (in a fancy way, but essentially big objects without references to Activity etc.). I have never seen this method used, so I have some doubts: Is this method safe to call to store arbitrary objects (in a sense

Why does the fragment's onCreateView, onCreate, onActivityCreated are called

点点圈 提交于 2019-11-29 20:11:27
I have an app, that deals with fragments and ViewPager. I have three fragments in a ViewPager. When you switch between them, it always causes the other two fragments to call their's onCreateView methods. How to do it only once, only when FragmentActivity is created??? I've read some questions and tried the solutions, but the fragments still have the same behavior. ListFragment onCreate called twice onCreate() and onCreateView() invokes a lot more than required (Fragments) Here is some code, if it helps you, guys: MainActivity: public class StartingActivity extends FragmentActivity implements

Android Google Maps API “Error inflating class fragment” [duplicate]

放肆的年华 提交于 2019-11-29 17:43:43
This question already has an answer here: After Google Play Service update to version 13 I got an error 8 answers A required meta-data tag in your app's AndroidManifest.xml does not exist. 9 answers I'm new to Android Development, I've started with something simple, just displaying a map centered on where I live. I've been trying many things to solve my problem, without any success, I'll leave here my code and the error log. I'll be really grateful if you can help me out ;] Error inflating class fragment: 01-10 03:04:51.632: E/AndroidRuntime(1366): FATAL EXCEPTION: main 01-10 03:04:51.632: E

NullPointerException: Attempt to read from field 'int android.app.Fragment.mContainerId' on a null object reference

孤人 提交于 2019-11-29 13:44:12
Having some interesting issue with transaction on fragments on Android Lollipop ONLY. Crash happens when i go back and remove previously added fragment. Here is stacktrace : FATAL EXCEPTION: main Process: com.parkme.consumer, PID: 15560 java.lang.NullPointerException: Attempt to read from field 'int android.app.Fragment.mContainerId' on a null object reference at android.app.BackStackRecord$1.onPreDraw(BackStackRecord.java:1131) at android.view.ViewTreeObserver.dispatchOnPreDraw(ViewTreeObserver.java:944) at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1970) at android.view

How do I resolve the authentication message that keeps popping up in a webview?

折月煮酒 提交于 2019-11-29 13:01:17
I have a webview with authentication, in which the authentication message keeps popping up for the webview fragment when called.The authentication popup is the fault code 410 (already signed in: sign in/cancel) message, How do I pass my cookies for the session id to be maintained? Any clues? thanks! P.S: Please explain programmatically with respect to my code wherever possible as it's hard to understand when you explain without code. Here is my code for the given fragment: public class WebViewFragment extends Fragment implements OnClickListener , MainActivity.BackPressListener<Fragment> {