Hi All,
After 15 days in the fabulous world of B4A, I'm developping a homewidget that should cycle the screen ON/OFF just before the lockscreen time out triggers.
I do this using:
- a Main activity in charge of UI and preferences management
- a widget service (based upon homewidget tuto) doing quite nothing but managing its icons and starting another service
- the other service rechedulled (startserviceat) based on events such as ScreenON or ScreenOFF ...
It used to work fine except sometimes when uploading a new version of the application it refuses to restart.
I get the msgbox (in french) ["Cycle Screen s'est arrêté" OK] which could be translated in Cycle screen self stopped or stopped by its own.
Under the debugger I see a Nullpointer exception
Installing file.
PackageAdded: package:anywheresoftware.b4a.samples.homewidgets
maininitializeProcessGlobals (java line: 475)
java.lang.RuntimeException: java.lang.NullPointerException
at anywheresoftware.b4a.samples.homewidgets.main.initializeProcessGlobals(main.java:475)
at anywheresoftware.b4a.samples.homewidgets.main.afterFirstLayout(main.java:85)
at anywheresoftware.b4a.samples.homewidgets.main.access$100(main.java:16)
at anywheresoftware.b4a.samples.homewidgets.main$WaitForLayout.run(main.java:74)
at android.os.Handler.handleCallback(Handler.java:615)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4898)
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:1006)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:773)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.NullPointerException
at anywheresoftware.b4a.keywords.Common.getComponentIntent(Common.java:735)
at anywheresoftware.b4a.objects.NotificationWrapper.SetInfo2(NotificationWrapper.java:141)
at anywheresoftware.b4a.objects.NotificationWrapper.SetInfo(NotificationWrapper.java:121)
at anywheresoftware.b4a.samples.homewidgets.widgetservice._process_globals(widgetservice.java:169)
at anywheresoftware.b4a.samples.homewidgets.main.initializeProcessGlobals(main.java:470)
... 12 more
My main does not include any ProcessGlobal variables.
I wonder if the problem is coming from a bad understanding of what does the StateManager ?
When in this state, it happens even that B4A_bridge does not succed to update the application.
I tried removing, the data application, stopping the application from APP mangement, sometimes with success but often without...
In other words, I'm stalled
Any help would be appreciated
Thanks
Alain
Here is my Main:
After 15 days in the fabulous world of B4A, I'm developping a homewidget that should cycle the screen ON/OFF just before the lockscreen time out triggers.
I do this using:
- a Main activity in charge of UI and preferences management
- a widget service (based upon homewidget tuto) doing quite nothing but managing its icons and starting another service
- the other service rechedulled (startserviceat) based on events such as ScreenON or ScreenOFF ...
It used to work fine except sometimes when uploading a new version of the application it refuses to restart.
I get the msgbox (in french) ["Cycle Screen s'est arrêté" OK] which could be translated in Cycle screen self stopped or stopped by its own.
Under the debugger I see a Nullpointer exception
Installing file.
PackageAdded: package:anywheresoftware.b4a.samples.homewidgets
maininitializeProcessGlobals (java line: 475)
java.lang.RuntimeException: java.lang.NullPointerException
at anywheresoftware.b4a.samples.homewidgets.main.initializeProcessGlobals(main.java:475)
at anywheresoftware.b4a.samples.homewidgets.main.afterFirstLayout(main.java:85)
at anywheresoftware.b4a.samples.homewidgets.main.access$100(main.java:16)
at anywheresoftware.b4a.samples.homewidgets.main$WaitForLayout.run(main.java:74)
at android.os.Handler.handleCallback(Handler.java:615)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4898)
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:1006)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:773)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.NullPointerException
at anywheresoftware.b4a.keywords.Common.getComponentIntent(Common.java:735)
at anywheresoftware.b4a.objects.NotificationWrapper.SetInfo2(NotificationWrapper.java:141)
at anywheresoftware.b4a.objects.NotificationWrapper.SetInfo(NotificationWrapper.java:121)
at anywheresoftware.b4a.samples.homewidgets.widgetservice._process_globals(widgetservice.java:169)
at anywheresoftware.b4a.samples.homewidgets.main.initializeProcessGlobals(main.java:470)
... 12 more
My main does not include any ProcessGlobal variables.
I wonder if the problem is coming from a bad understanding of what does the StateManager ?
When in this state, it happens even that B4A_bridge does not succed to update the application.
I tried removing, the data application, stopping the application from APP mangement, sometimes with success but often without...
In other words, I'm stalled
Any help would be appreciated
Thanks
Alain
Here is my Main:
B4X:
Sub Process_Globals
'These global variables will be declared once when the application starts.
'These variables can be accessed from all modules.
End Sub
Sub Globals
Dim p As Phone
Dim lock_TO As Int
Dim SeekBar_sect As SeekBar
Dim SeekBar_Batt As SeekBar
Dim Label_Sect As Label
Dim Label_Batt As Label
Dim Bt_wifi As Button
Dim mywifi As ABWifi
Dim Ed_wifi As EditText
Dim Label_wifi As Label
Dim SeekBar_wifi As SeekBar
Dim Vibrate As PhoneVibrate ' For phone vibration
End Sub
Sub Activity_Create(FirstTime As Boolean)
If FirstTime Then
ToastMessageShow("Go to the home screen and add the Screen Cycle Widget.", False)
End If
Activity.LoadLayout("ihm_radio")
lock_TO = 5*60 - p.GetSettings("screen_off_timeout")/1000
SeekBar_sect.Max = 300
SeekBar_wifi.Max = 800
SeekBar_Batt.Max = 60
Try
If StateManager.RestoreState(Activity, "Main", 0) = False Then
ToastMessageShow("terstore false.", False)
'set the default values
StateManager.SetSetting("counter_secteur", 100)
StateManager.SetSetting("counter_Batt", 5)
StateManager.SetSetting("counter_wifi", 100)
SeekBar_sect.Value = 300
SeekBar_wifi.Value = 300
SeekBar_Batt.Value = 15
Label_Sect.Text = "secteur : " & 300 & " min"
Label_Batt.Text = "batterie : " & 15 & " min"
Label_wifi.Text = "wifi : " & 300 & " min"
Ed_wifi.Text = "---- click here ---->"
StateManager.SetSetting ("my_wifi", "---")
StateManager.SaveSettings
End If
Catch
Vibrate.Vibrate(100)
End Try
'Activity.Finish
End Sub
Sub Activity_Resume
Log("tttt")
'ToastMessageShow("resume.", False)
End Sub
Sub Activity_Pause (UserClosed As Boolean)
' If UserClosed Then
' StateManager.ResetState("Main")
' Else
StateManager.SaveState(Activity, "Main")
' End If
StateManager.SaveSettings
End Sub
Sub SeekBar_sect_ValueChanged (Value As Int, UserChanged As Boolean)
Label_Sect.Text = "secteur : " & Value & " min"
lock_TO = 5*60 - p.GetSettings("screen_off_timeout")/1000
StateManager.SetSetting("counter_secteur", Value*60 / lock_TO)
StateManager.SaveSettings
End Sub
Sub SeekBar_Batt_ValueChanged (Value As Int, UserChanged As Boolean)
Label_Batt.Text = "Batterie : " & Value & " min"
lock_TO = 5*60 - p.GetSettings("screen_off_timeout")/1000
StateManager.SetSetting("counter_secteur", Value*60 / lock_TO)
StateManager.SaveSettings
End Sub
Sub Bt_wifi_Click
Dim r As Boolean
Dim s As String
r = mywifi.ABLoadWifi()
If r = True Then
s = mywifi.ABGetCurrentWifiInfo().SSID
If s = Null Then s = "no wifi"
Ed_wifi.Text = s
Else
Ed_wifi.Text = "click to add friend wifi ! ====>"
End If
StateManager.SetSetting("my_wifi", Ed_wifi.text)
StateManager.SaveSettings
End Sub
Sub Ed_wifi_TextChanged (Old As String, New As String)
StateManager.SetSetting("my_wifi", Ed_wifi.text)
StateManager.SaveSettings
End Sub
Sub SeekBar_wifi_ValueChanged (Value As Int, UserChanged As Boolean)
Label_wifi.Text = "wifi : " & Value & " min"
lock_TO = 5*60 - p.GetSettings("screen_off_timeout")/1000
StateManager.SetSetting("counter_wifi", Value*60 / lock_TO)
StateManager.SaveSettings
End Sub