Nested PreferenceFragmentCompat not displayed on Android 4.4 - android

I recently refactored my Android app to use PreferenceFragmentCompat instead of the deprecated PreferenceActivity + PreferenceFragment.
The app uses a hierarchy of multiple preference screens.
I followed this article on the Android docs: https://developer.android.com/guide/topics/ui/settings/organize-your-settings
This seemed to be working fine, until I noticed that under Android 4.4 the nested PreferenceFragments are not displayed - nothing at all happens when I click the Preferences on my main preferences screen.
There are no warnings and errors in the logs and according to the debug logs onCreate and onResume of the nested fragments are called.
I created a minimum sample to reproduce the issue.

I just fixed the issue by replacing the <fragment> tag in the Activity that hosts my main PreferenceFragmentCompat with a <androidx.fragment.app.FragmentContainerView>.
See this commit for details.
I'm not sure if that's a bug in the Android APIs or if I missed anything else.

Related

lifecycle-process: app crash when importing dependency

I was using lifecycle extensions library for a while, but I notice that when updating from 2.1.0 to 2.2.0 the app crash systematically when opening a draggable view. Since the library has been reworked, and the code I use is now in lifecycle-process. But even with the latest alpha version (2.3.0-alpha07) the crash is here. The crash only occurs on API 29 and above.
I've a legacy code for a draggable view that creates a fragment transaction on the pre-draw of the Activity. If I don't add the lib dependency the Fragment is Resumed on the Activity pre-draw, when I add the lib dependency (even if no code used) the Fragment is only Initialized on the Activity pre-draw.
I understand the lib ContentProvider starts even if I don't need it, but I'm not sure what is causing this Fragment lifecycle change. I found that the ReportFragment has worrying comments and a API>=29 check, so if you can help on that, thanks!
https://cs.android.com/androidx/platform/frameworks/support/+/androidx-master-dev:lifecycle/lifecycle-runtime/src/main/java/androidx/lifecycle/ReportFragment.java;l=41
PS: If I use commitNow instead of commit in my DraggingView, I don't see the crash anymore. But I want to understand that to be sure it's ok in the rest of my app.
PS2: I tried to create a SSCCE but I cannot reproduce the issue outside of my app, and I can't share my entire app :/

In android 4.4.2 Activity resuming loads the default fragment

In my app i have noticed a strange behaviour in android 4.4.2. I am using a Sherlock Navigation Drawer to show side drawer and replacing fragments to load differnt pages within the same activity.But after minimizing the application and relaunching in android 4.4.2 its loading the default fragmant but in other versions of android its resuming to the fragment from where i left. I have tested with the versions 4.2.2,4.1.2,4.0.2,2.3.3 and its working as i expected and the issue occurs only in android 4.4.2
any help is appriciated....
I think for this reason you are facing problem in 4.4.2 just check the reason is, that the creator of ActionBarSherlock, Jake Wharton, announced on Google+ that further development of ActionBarSherlock has been stopped. ActionBarSherlock 4.4 is the last release and might get bug fixes – but there won’t be any new features:
While there may be a dot release or two in the coming weeks, version 4.4
is shaping up to be The Last Release.
For more please check the https://www.grokkingandroid.com/migrating-actionbarsherlock-actionbarcompat/
I don't know why this may happen but you can do some precautions to avoid this. Save the current active fragment position in a SharedPreference or inside onSaveInstanceState method and inside onResume() of your activity check if it is not the currently selected, replace it.

Android Studio create new activity requires fragment

I have been away from Android app creation for quite a while and has just recently begun my new App.
Now i thought i would test out this new Android Studio and therefore downloaded it.
When i started my project it asked for a fragment and i wasnt quite sure what it ment (i know what a fragment is!).
When it started the project i had a activity_main and a fragment_main. And now every time i want to create a new activity it requires me to create an additional fragement.
Can anyone explain to me why this is happening (maybe ive missed something).
Fragments are part of Google's UI design philosophy since Honeycomb (see embedded link).
If you would like to work around the default activity template in Android Studio, then check out this blog post.
To add an Activity without a fragment, select File->New->Activity->Empty Activity

MVVMCROSS Fragment sample not working with rotation

I just started out with learning how to use MVVMCross with Android using Xamarin Studio. I am fairly new to Android development.
I am porting an iOS app to Android and when I rotate my screen my app crashes when using fragments. I thought the problem was just me doing something wrong but when I run the sample project attached to the sample video the same thing happens. The error i get is " No default constructor found".
The Sample app I used at github : https://github.com/MvvmCross/MvvmCross-Tutorials/tree/master/Fragments
Can someone please help me out to why this is happening ?
After some digging, I "think" you are asking about how to handle rotation for a DialogFragment - I hope I've got that right.
If you do want to handle rotation in Android, then you have to:
provide the default constructor and you have to make use of the fragment tag
provide some code in the Activity.OnCreate handler in order to ensure that the DialogFragment has its ViewModel set after the rotation occurs.
I've just done this for the sample you mention in this commit - https://github.com/MvvmCross/MvvmCross-Tutorials/commit/ebe1777ec79ee2607b1b863f6b8b3911c12df53f
Note that to really fully support the Activity lifecycle - e.g. including loading/saving state when the App or Activity is "tombstoned" - then you should also go further than this - should save/restore all View and ViewModel state. MvvmCross does contain some helpers for this in the SaveState and ReloadState ViewModel methods - but even with these then fully supporting the Activity lifecycle can be quite a pain (which is why some apps don't fully support it, but instead show a "new" display instead)

java.lang.IllegalStateException in Android 3.x and 4.x ; Works fine on 2.x

I am using TabActivity which contains Four tabs. For every tab I am using ActivityGroup and inside ActivityGroup I have several activities. In one of my Activity I have a Google Map. Whenever I click on the built in Back button in Google Map Activity I am getting the below Exception.
android java.lang.illegalstateexception can not perform this action after onsaveinstancestate.
I am getting the above Exception in 3.x and 4.x Android versions. But in 2.x it is working fine without any Exception.
Please post your code. Otherwise, no point of discussion.
As far as I know, you may pass wrong parameters or using the same API twice.
are you using startmanaging cursor anywhere in the code for this activity.
This works fines for 2.3 OS but 3.0 onwards it throws error. I also faced same situation, the way to resolve is the add startmanaging cursor only in 2.3 below OS.

Categories

Resources