Android Tutorial PreferenceActivity tutorial

joseluis

Active Member
Licensed User
Longtime User
How can I find out the name of the preferences screens activities? I want to apply styles to them in the manifest editor (notitlebar, fullscreen, etc), and I tried to use reflection lib to find that data, unsuccessfully.
 

sigster

Active Member
Licensed User
Longtime User
Can I get GetBoolean from the Checkbox when the program start to use in SQL.ExecQuery

Regards
Sigster
 

sigster

Active Member
Licensed User
Longtime User
Thanks

B4X:
   If manager.GetBoolean("check1") = True Then
   ToastMessageShow("Yes", False)
   Else
   ToastMessageShow("No", False)
   End If

Regards
Sigster
 

sigster

Active Member
Licensed User
Longtime User
You don't have radio button

so do you have Check1_CheckedChanged
so I can stop user select both check1 and 2

Regards
Sigster
 

kanaida

Active Member
Licensed User
Longtime User
Thanks. This is exactly what I was looking for :sign0142:

Now I can concentrate on the real parts of my app rather than the low level ui/db stuff. That stuff can wear you out quick
 

luke2012

Well-Known Member
Licensed User
Longtime User
App Crash calling CreatePreferenceScreen ()

My log is :

Starting: Intent { flg=0x20000 cmp=luke2012.android.pizzeria/anywheresoftware.b4a.objects.preferenceactivity (has extras) } from pid 17585
** Activity (main) Pause, UserClosed = false **
Shutting down VM
threadid=1: thread exiting with uncaught exception (group=0x40015568)
java.lang.RuntimeException: Unable to start activity ComponentInfo{luke2012.android.pizzeria/anywheresoftware.b4a.objects.preferenceactivity}: java.lang.NullPointerException
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1664)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1680)
at android.app.ActivityThread.access$1500(ActivityThread.java:117)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:931)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:130)
at android.app.ActivityThread.main(ActivityThread.java:3703)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:507)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:841)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:599)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.NullPointerException
at anywheresoftware.b4a.objects.preferenceactivity$PreferenceScreenWrapper.createPreference(preferenceactivity.java:169)
at anywheresoftware.b4a.objects.preferenceactivity.onCreate(preferenceactivity.java:41)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1628)
... 11 more
FATAL EXCEPTION: main
java.lang.RuntimeException: Unable to start activity ComponentInfo{luke2012.android.pizzeria/anywheresoftware.b4a.objects.preferenceactivity}: java.lang.NullPointerException
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1664)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1680)
at android.app.ActivityThread.access$1500(ActivityThread.java:117)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:931)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:130)
at android.app.ActivityThread.main(ActivityThread.java:3703)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:507)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:841)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:599)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.NullPointerException
at anywheresoftware.b4a.objects.preferenceactivity$PreferenceScreenWrapper.createPreference(preferenceactivity.java:169)
at anywheresoftware.b4a.objects.preferenceactivity.onCreate(preferenceactivity.java:41)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1628)
... 11 more
Force finishing activity luke2012.android.pizzeria/anywheresoftware.b4a.objects.preferenceactivity
Force finishing activity luke2012.android.pizzeria/.main
Activity pause timeout for HistoryRecord{40a81540 luke2012.android.pizzeria/anywheresoftware.b4a.objects.preferenceactivity}


Any suggestions ?

Thanks!
 

luke2012

Well-Known Member
Licensed User
Longtime User
I declared it in the Process_Global :

Dim screen As PreferenceScreen
 

CharlesIPTI

Active Member
Licensed User
Longtime User
Dont Hurt Me Im Just Asking smile smile

OK So its been like a year does this thing have events yet

:icon_clap: I'm just saying I like it I'm gonna use it but yea ....


Wheres the News section of this forum for new up coming stuff ??

Are we getting user classes any time soon..like within my project's deadline date maybe ??
 

mitsusdev

Member
Licensed User
Longtime User
Manager.GetBoolean with the key of the checkbox will return its state.

Hi,
i run PreferenceActivity into my app. It work fine for Android 2.3.x, but on ICS it CRASH when i try to call:

B4X:
StartActivity(screen.CreateIntent)

Below IDE logs:

B4X:
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.acotel.myhealth/anywheresoftware.b4a.objects.preferenceactivity}: java.lang.ClassCastException: java.lang.String cannot be cast to java.lang.Boolean


   at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1956)
   at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1981)
   at android.app.ActivityThread.access$600(ActivityThread.java:123)
   at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1147)
   at android.os.Handler.dispatchMessage(Handler.java:99)
   at android.os.Looper.loop(Looper.java:137)
   at android.app.ActivityThread.main(ActivityThread.java:4424)
   at java.lang.reflect.Method.invokeNative(Native Method)
   at java.lang.reflect.Method.invoke(Method.java:511)
   at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
   at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
   at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.ClassCastException: java.lang.String cannot be cast to java.lang.Boolean


   at android.app.SharedPreferencesImpl.getBoolean(SharedPreferencesImpl.java:242)
   at android.preference.Preference.getPersistedBoolean(Preference.java:1627)
   at android.preference.TwoStatePreference.onSetInitialValue(TwoStatePreference.java:184)
   at android.preference.Preference.dispatchSetInitialValue(Preference.java:1312)
   at android.preference.Preference.onAttachedToHierarchy(Preference.java:1124)
   at android.preference.PreferenceGroup.addPreference(PreferenceGroup.java:156)
   at anywheresoftware.b4a.objects.preferenceactivity$PreferenceScreenWrapper.createPreference(preferenceactivity.java:227)
   at anywheresoftware.b4a.objects.preferenceactivity$PreferenceCategoryWrapper.createPreference(preferenceactivity.java:453)
   at anywheresoftware.b4a.objects.preferenceactivity$PreferenceScreenWrapper.createPreference(preferenceactivity.java:224)
   at anywheresoftware.b4a.objects.preferenceactivity.onCreate(preferenceactivity.java:65)
   at android.app.Activity.performCreate(Activity.java:4465)
   at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1049)
   at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1920)
   ... 11 more

Where are my errors?

THX
 

mitsusdev

Member
Licensed User
Longtime User
Have you changed the type of one of the fields? This error happens because the saved value is of type String and you are not trying to treat it as boolean.

You can manually uninstall the app to delete the current settings file.

Hi,
below mi CreatePreferenceScreen Code:
B4X:
Sub CreatePreferenceScreen
   screen.Initialize("Impostazioni", "")
   Dim intentCat, cat1, cat2 As AHPreferenceCategory
   Dim intentScreen As AHPreferenceScreen
   
   intentCat.Initialize("Notifiche")
   intentCat.AddCheckBox("intentenable", "Abilita notifiche", "Notifiche abilitate", "Notifiche disabilitate", True, "")
   intentScreen.Initialize("Avanzate", "Preferenze notifiche")
   intentScreen.AddRingtone("ring1", "Avviso acustico", "Suoneria notifiche", "", "", intentScreen.RT_NOTIFICATION)
   
   intentScreen.AddCheckBox("chktts", "Abilita Text To Speech", "Text To Speech abilitato", "Text To Speech disabilitato", False, "")
   
'    Open Webbrowser using PhoneIntents
   Dim pi As PhoneIntents
   intentScreen.AddIntent("Maggiori informazioni", "Vai al sito web www.xxxxx.com", pi.OpenBrowser("http://www.xxxx.com"), "")

'    Add the screen with the intents calls to the category
   intentCat.AddPreferenceScreen(intentScreen, "intentenable")
      
   'add the categories to the main screen
   screen.AddPreferenceCategory(intentCat)
   
End Sub
 

mitsusdev

Member
Licensed User
Longtime User
Have you tried to manually uninstall your app and then run it?

Yes. i've tryed, but it crash more...it work only if i comment the line:

B4X:
......
' intentCat.AddPreferenceScreen(intentScreen, "intentenable")
 
Cookies are required to use this site. You must accept them to continue using the site. Learn more…