If I call PhoneEvents.StopListening I can not reinitialize the PE Object.
I have this small test program:
I get this error if I press the update button:
It only works if I reDIM the pe Object in btUpdate_Click()
I have this small test program:
B4X:
'Activity module
Sub Process_Globals
'These global variables will be declared once when the application starts.
'These variables can be accessed from all modules.
Dim pe As PhoneEvents
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 edBattLevel As EditText
Dim edStatus As EditText
Dim btUpdate As Button
End Sub
Sub Activity_Create(FirstTime As Boolean)
Activity.LoadLayout("main1.bal")
pe.Initialize("PE")
End Sub
Sub Activity_Resume
End Sub
Sub Activity_Pause (UserClosed As Boolean)
End Sub
Sub PE_BatteryChanged (Level As Int, Scale As Int, Plugged As Boolean, Intent As Intent)
ToastMessageShow("Data Updated", False)
edBattLevel.Text = Level
edStatus.Text = Intent.GetExtra("status")
pe.StopListening
End Sub
Sub btUpdate_Click
pe.Initialize("PE")
End Sub
I get this error if I press the update button:
B4X:
** Activity (main) Create, isFirst = true **
** Activity (main) Resume **
** Activity (main) Create, isFirst = true **
** Activity (main) Resume **
** Activity (main) Create, isFirst = true **
** Activity (main) Resume **
main_btupdate_click (B4A line: 41)
pe.Initialize("PE")
java.lang.IllegalArgumentException: Receiver not registered: anywheresoftware.b4a.phone.PhoneEvents$14@4685a528
at android.app.ActivityThread$PackageInfo.forgetReceiverDispatcher(ActivityThread.java:793)
at android.app.ContextImpl.unregisterReceiver(ContextImpl.java:845)
at android.content.ContextWrapper.unregisterReceiver(ContextWrapper.java:331)
at anywheresoftware.b4a.phone.PhoneEvents.StopListening(PhoneEvents.java:235)
at anywheresoftware.b4a.phone.PhoneEvents.Initialize(PhoneEvents.java:196)
at de.amberhome.batterymonitor.main._btupdate_click(main.java:212)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:521)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:99)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:89)
at anywheresoftware.b4a.BA.raiseEvent(BA.java:85)
at anywheresoftware.b4a.objects.ViewWrapper$1.onClick(ViewWrapper.java:49)
at android.view.View.performClick(View.java:2408)
at android.view.View$PerformClick.run(View.java:8816)
at android.os.Handler.handleCallback(Handler.java:587)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:123)
at android.app.ActivityThread.main(ActivityThread.java:4627)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:521)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:860)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
at dalvik.system.NativeStart.main(Native Method)
java.lang.IllegalArgumentException: Receiver not registered: anywheresoftware.b4a.phone.PhoneEvents$14@4685a528
It only works if I reDIM the pe Object in btUpdate_Click()