android-fragmentactivity

FragmentManager NullPointerException when trying to commitAllowingStateLoss

馋奶兔 提交于 2019-12-04 03:47:21
Context: I have an Activity with a Fragment and 3 InnerFragments . When the Fragment onDestroy() is called, I want to remove the inner fragments from the FragmentManager . The code from onDestroy() is below. Problem: FragmentManager throws NullPointerException , probably when commitAllowingStateLoss() is called. I don't understand why. @Override public void onDestroy() { super.onDestroy(); if (getFragmentManager().findFragmentById(R.id.fragment_framelayout_left) != null) { FragmentTransaction fragmentTransaction = getFragmentManager().beginTransaction(); fragmentTransaction.remove

How to start Fragment from Activity?

夙愿已清 提交于 2019-12-04 03:23:11
问题 I have one Fragment: ProductsFragments extends Fragment and one Activity AdminMenuActivity extends ActionBarActivity I want to call ProductsFragments from AdminMenuActivity. I have used 2 options: 1) FragmentManager fm = getSupportFragmentManager(); for(int i = 0; i < fm.getBackStackEntryCount(); ++i) { fm.popBackStack(); } FragmentTransaction tx = getSupportFragmentManager().beginTransaction(); tx.replace(R.id.frame_layout, android.support.v4.app.Fragment.instantiate(AdminMenuActivity.this,

how to set toolbar on FragmentActivity?

泪湿孤枕 提交于 2019-12-03 23:35:43
I want to set toolbar on my activity which extends FragmentActivity . I know that for use setSuppoertActionBar(toolbar) method we extends AppCompatActivity instead of FragmentActivity but I override the onMenuItemSelected(int featureId, MenuItem item) method which is final in AppCompatActivity and final method cannot override. so I'm restricted to extends FragmentActivity . Here is my code: public class MainActivity extends FragmentActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); Toolbar

how to open WifiDisplay Setting from another app?

早过忘川 提交于 2019-12-03 22:30:31
I want to open Android4.2 setting WifiDisplaySettingsActivity from my app. I tried Intent i; PackageManager manager = getActivity().getPackageManager(); try { i = manager.getLaunchIntentForPackage("com.android.settings.wfd"); if (i == null) throw new PackageManager.NameNotFoundException(); i.addCategory(Intent.ACTION_MAIN); startActivity(i); } catch (PackageManager.NameNotFoundException e) { } and final Intent intent = new Intent(Intent.ACTION_MAIN, null); intent.addCategory(Intent.CATEGORY_LAUNCHER); final ComponentName cn = new ComponentName("com.android.settings.wfd","com.android.settings

Where Fragment save its State when FragmentTransaction.Replace?

余生长醉 提交于 2019-12-03 21:40:25
Backgroud: i have a menu on the left, and different scrollable contents on the right. i wanted to save the scrolled position. But i failed. Then ... I have set up a very simple project to test it. In words, i have a menu on the left, and different contents all holding an <EditText> on the right. (of the same class though, they are of different instances) In codes, (very simple) content.xml <EditText xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/text" android:layout_width="match_parent" android:layout_height="wrap_content" android:hint="Please save my text ..." />

How to navigate from one Fragment to another?

那年仲夏 提交于 2019-12-03 21:19:22
Here is my code: activity_main.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" android:paddingBottom="@dimen/activity_vertical_margin" android:paddingLeft="@dimen/activity_horizontal_margin" android:paddingRight="@dimen/activity_horizontal_margin" android:paddingTop="@dimen/activity_vertical_margin" tools:context=".MainActivity" > <android.support.v4.view.ViewPager android:id="@+id/pager" android:layout_width="fill_parent" android:layout_height=

Android Lifecycle management of Fragments within ViewPager and FragmentPagerAdapter

眉间皱痕 提交于 2019-12-03 19:11:27
问题 I have been struggling to find out what the correct management of Fragments within a FragmentActivity with a ViewPager is. Before I go into details, a quick summary of the issue that I am facing is the following: I have a FragmentActivity with a ViewPager . The ViewPager uses a custom, yet very simple FragmentPagerAdapter . Each Fragment within the ViewPager comprises of an ExpandableListView . I also have an action bar button called "Refresh". For now, let's assume that the ViewPager has

Intercepting ActionBar Home button in Fragment

ぃ、小莉子 提交于 2019-12-03 16:23:19
I can successfully intercept the ActionBar home button from my NavigationDrawerFragment , which is added to my MainActivity , like so: @Override public boolean onOptionsItemSelected(MenuItem item) { if (!loggedIn() && item.getItemId() == android.R.id.home) { login(); return true; } return super.onOptionsItemSelected(item); } However, in my ComposeActivity with ComposeFragment this does not work. onOptionsItemSelected is not called on the fragment. I have debugged the code and the issue seems to come down to the design of the Android support library. It appears that both FragmentActivity and

Can fragment be created with only one instance

送分小仙女□ 提交于 2019-12-03 16:21:46
I was just wondering, can fragment creation only have one instance or singleton? I went through Google iosched project too. They simply create Fragment a = new Fragment(); Whenever they want... Suppose eg: public static FragmentManager instance; public static FragmentManager getInstance() { if (instance == null) { instance = new FragmentManager(); } return instance; } public TestFragment getTestFragment() { if (testFragment == null) { testFragment = new TestFragment (); } return testFragment } } Can I use everywhere FragmentManager.getInstance().getTestFragment() for transaction? eg:

how to disable ViewPager swiping using android-support-v4.jar in android

只谈情不闲聊 提交于 2019-12-03 13:36:35
问题 I'm creating a android application with target on 2.2. I still want to use the ViewPager provided in the android.support-v4.jar.i want need to disable Viewpager swipping on button click.i have use following code for disable. but its don't work. public class ServiesDeail extends FragmentActivity{ ServiesTitleFragmentAdapter mAdapter; ViewPager mPager; int position = 0 ; @SuppressWarnings({ "rawtypes", "unchecked" }) @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate