1

I want to transpose the project below api level 22 to api level 28

I stay taking PreferenceActivity of project links below and I put PreferenceFragmentCompat: [1]:http://ryanfx.blogspot.com/2013/06/raspberry-pi-powered-android-controlled.html

This is my current code:[2]:https://github.com/ryanfx/GarageAndroid/blob/master/src/com/blogspot/ryanfx/activity/ConfigurationActivity.java

I have issue of the picture below and this is my project (with issue):[3]:https://github.com/neuberfran/AlarmController/blob/master/app/src/main/java/com/blogspot/neuberfran/activity/ConfigurationActivity.java

issue4

What is the best way to transpose project with PreferenceActivity/appcompat-v7:28.0.0 to androidx/PreferenceFragmentCompat ?

neuberfran
  • 359
  • 3
  • 18
  • What do you mean "transpose"? Have you tried the tool of the IDE to convert to Android-x ? – android developer Jul 02 '19 at 19:36
  • @android developer Hi, I put api 28 in build.gradle and clicked on menu -> refactor -> migrate to AndroidX, and in file ConfigurationActivity.kt there was no automatic exchange of PreferenceActivity to PreferenceFragmentCompat. the two screens below, show my issue. In the second, I do not have the AccountManager correctly, because of the first. https://drive.google.com/file/d/1wDzAW-1TbDJ924VS97YGuSd8nBOe3GgT/view?usp=sharing https://drive.google.com/file/d/18tMJruFJMWGFEPeodbkiwr9uA7p8cHq6/view?usp=sharing – neuberfran Jul 02 '19 at 22:11
  • 2
    You have `setPreferencesFromResource` commented out in your project? You need to call that method before you try and call `findPreference`, or else it will just return null You should do this inside onCreatePreferences, not onCreate - see the sample project [here](https://github.com/googlesamples/android-preferences/blob/master/app/src/main/java/com/example/androidx/preference/sample/MainActivity.kt) for an example – Louis Jul 02 '19 at 22:20
  • @Louis I have new issues now: https://drive.google.com/drive/folders/1muTuwozTJ7bSA5bVX-y8RKmlWdWIneMV?usp=sharing https://drive.google.com/file/d/19azy3sJa5WJHISaPSY3v9t7_PxWIHusZ/view?usp=sharing – neuberfran Jul 03 '19 at 04:04
  • 2
    For the first issue, your 'ConfigurationActivity' is not an activity, it is now a Fragment, so you need to pass `getContext()` instead of `this`. For the second issue, remove all `android.preference` imports, and make sure you are only importing the `androidx.preference` classes - you cannot mix both together – Louis Jul 03 '19 at 11:10
  • @Louis new Issue https://drive.google.com/file/d/1HHUwyf7pJ-P0rSZiEBW_ECYAECJGMcYc/view?usp=sharing – neuberfran Jul 03 '19 at 18:07
  • Yes, this is now a Fragment, not an activity. So you need to use the `supportFragmentManager` to show the fragment inside an activity, you can't launch this fragment directly. – Louis Jul 03 '19 at 18:10
  • @Louis work (more or less) only with getSupportFragmentManager but not with supportFragmentManager AND accountmanager issue remains. https://drive.google.com/drive/folders/1BUepzWxB1FDWpgMD2CquP0XAqZ6UgmZ8?usp=sharing – neuberfran Jul 03 '19 at 20:47
  • 2
    Yes, `getSupportFragmentManager` is correct - I don't understand what is happening in the account screenshot. Can you update the github repo with the new code? – Louis Jul 03 '19 at 23:21
  • @Louis https://github.com/neuberfran/GarageAndroid-master/blob/master/app/src/main/java/com/blogspot/ryanfx/activity/MainActivity.java – neuberfran Jul 04 '19 at 00:10
  • @Louis I think supportFragmentManager only works with kotlin and androidx/ktx or in Java with appcompat-v7/v8. I'm checking cases on the internet: https://www.youtube.com/watch?v=PS9jhuHECEQ https://blog.mindorks.com/implementing-android-jetpack-preferences https://code.luasoftware.com/tutorials/android/android-how-to-implement-listpreference/ – neuberfran Jul 04 '19 at 00:18
  • 2
    Ok, so the issue is you are setting the activity's view, and also adding a fragment to your activity: setContentView(R.layout.activity_main); supportFragmentManager.beginTransaction() .replace(R.id.content, new ConfigurationActivity () ); .commit(); It looks like you actually want a separate activity, that displays the settings. So just rename ConfigurationActivity to ConfigurationFragment, create a new ConfigurationActivity that extends AppCompatActivity, and make it show the fragment. And then in MainActivity, you just link to configuration activity like before – Louis Jul 04 '19 at 00:19
  • 2
    supportFragmentManager and getSupportFragmentManager() are the same thing, the first one is just the Kotlin syntax to access it. – Louis Jul 04 '19 at 00:21
  • @Louis First, we have to undo a mess. The code: supportFragmentManager .beginTransaction() .replace(R.xml.server_config, new ConfigurationActivity () ); .commit() is not working. I changed the code there and got a new error. https://drive.google.com/file/d/1hAl7TSgY4nvTQ9zjo-o7T2qr8cidUUNn/view?usp=sharing I think I need put – neuberfran Jul 04 '19 at 01:13
  • @Louis, Ok now I'm back to this issue:https://drive.google.com/file/d/1GqOaVjDmmtUOlmjtuVZ1XxOfgFVqEndz/view?usp=sharing and I will try the changes proposed by you. with getSupportFragmentManager and not with supportFragmentManager. This is new issue with changes: https://drive.google.com/file/d/11s2Dn61kADP9lJNeIwjs5N5LetEU4aRr/view?usp=sharing after I clicked in Settings menu. – neuberfran Jul 04 '19 at 01:37
  • 1
    Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/195985/discussion-between-louis-and-neuber). – Louis Jul 04 '19 at 10:53

0 Answers0