Android Question AHPreference screen does not want to show

Gawro777

Member
Licensed User
Longtime User
Hi everyone,

I have problem with really simple code. I just strarted ant want to create AHPreferenceScreen, but it does not work and gives a lot o errors.

What do I miss?

Here is all the code:

B4X:
#Region  Project Attributes
    #ApplicationLabel: mytestapp
    #VersionCode: 01
    #VersionName:
    'SupportedOrientations possible values: unspecified, landscape or portrait.
    #SupportedOrientations: unspecified
    #CanInstallToExternalStorage: False
#End Region

#Region  Activity Attributes
    #FullScreen: False
    #IncludeTitle: True
#End Region

Sub Process_Globals
    'These global variables will be declared once when the application starts.
    'These variables can be accessed from all modules.
    Dim prefmanager As AHPreferenceManager
    Dim screen As AHPreferenceScreen
    Dim cal As MyCalendar
End Sub

Sub Globals
    'These global variables will be redeclared each time the activity is created.
    'These variables can only be accessed from this module.
    Dim calmap As Map
End Sub

Sub Activity_Create(FirstTime As Boolean)
    'Do not forget to load the layout file created with the visual designer. For example:
    'Activity.LoadLayout("Layout1")
    If FirstTime Then
        CreatePrefScreen
        StartActivity (screen.CreateIntent)
    End If
End Sub

Sub CreatePrefScreen
    screen.Initialize("Preferences", "")
    Dim cat1, cat2 As AHPreferenceCategory
   
    cal.Initialize
    calmap.Initialize
   
    calmap = cal.GetListOfAllCalendars(True)
    cat1.Initialize("Calendars")
    cat1.AddList2("kalendarze", "tytuł", "summary", "default", "dependency", calmap)
   
    cat2.Initialize("Examples")
    cat2.AddCheckBox("check1", "Checkbox1", "This is Checkbox1 without second summary", "", True, "")
    cat2.AddEditText("edit1", "EditText1", "This is EditText1", "", "check1")
    cat2.AddEditText2("edit2", "EditText2", "This is a number input field", "1", 2, False, True, "")
       
    'add the categories to the main screen
    screen.AddPreferenceCategory(cat1)
    screen.AddPreferenceCategory(cat2)
End Sub

Sub Activity_Resume

End Sub

Sub Activity_Pause (UserClosed As Boolean)

End Sub


Here is the list of errors:
Installing file.
PackageAdded: package:b4a.example
** Activity (main) Create, isFirst = true **
Error occurred on line: 34 (Main)
android.content.ActivityNotFoundException: Unable to find explicit activity class {b4a.example/de.amberhome.objects.preferenceactivity}; have you declared this activity in your AndroidManifest.xml?
at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1854)
at android.app.Instrumentation.execStartActivity(Instrumentation.java:1545)
at android.app.Activity.startActivityForResult(Activity.java:4283)
at android.app.Activity.startActivityForResult(Activity.java:4230)
at android.app.Activity.startActivity(Activity.java:4567)
at android.app.Activity.startActivity(Activity.java:4535)
at anywheresoftware.b4a.keywords.Common.StartActivity(Common.java:698)
at b4a.example.main._activity_create(main.java:384)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:708)
at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:337)
at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:247)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:134)
at b4a.example.main.afterFirstLayout(main.java:102)
at b4a.example.main.access$000(main.java:17)
at b4a.example.main$WaitForLayout.run(main.java:80)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:158)
at android.app.ActivityThread.main(ActivityThread.java:7229)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1230)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1120)
** Activity (main) Resume **
** Activity (main) Resume **

Anyone please help?
 

chefe82

Member
Licensed User
Longtime User
Add to manifest

B4X:
AddApplicationText(<activity android:name="anywheresoftware.b4a.objects.preferenceactivity"/>)
 
Upvote 0

Gawro777

Member
Licensed User
Longtime User
Add to manifest

B4X:
AddApplicationText(<activity android:name="anywheresoftware.b4a.objects.preferenceactivity"/>)

Thanks for mega-quick reply! But...

My manifest file now looks like this:

B4X:
'This code will be applied to the manifest file during compilation.
'You do not need to modify it in most cases.
'See this link for for more information: https://www.b4x.com/forum/showthread.php?p=78136
AddManifestText(
<uses-sdk android:minSdkVersion="5" android:targetSdkVersion="19"/>
<supports-screens android:largeScreens="true"
    android:normalScreens="true"
    android:smallScreens="true"
    android:anyDensity="true"/>)
SetApplicationAttribute(android:icon, "@drawable/icon")
SetApplicationAttribute(android:label, "$LABEL$")
'End of default text.
AddApplicationText(<activity android:name="anywheresoftware.b4a.objects.preferenceactivity"/>)

And I got error:

android.content.ActivityNotFoundException: Unable to find explicit activity class {b4a.example/de.amberhome.objects.preferenceactivity}; have you declared this activity in your AndroidManifest.xml?

:(
 
Upvote 0

Gawro777

Member
Licensed User
Longtime User
Done.
Added this line to manifest:
AddApplicationText(<activity android:name="de.amberhome.objects.preferenceactivity"/>)
It works. Thanks again.
 
Upvote 0
Top