Android Question java.lang.IllegalStateException in xxxx.main.onCreate (only Android 9)

Tempomaster

Active Member
Licensed User
Longtime User
Hello,

I am increasingly getting an error message. I do not know why this error occurs. Therefore I can not think of an elimination at the moment. For a hint for troubleshooting I would be very grateful.

B4X:
java.lang.RuntimeException:
 
  at android.app.ActivityThread.performLaunchActivity (ActivityThread.java:3115)
 
  at android.app.ActivityThread.handleLaunchActivity (ActivityThread.java:3258)
 
  at android.app.servertransaction.LaunchActivityItem.execute (LaunchActivityItem.java:78)
 
  at android.app.servertransaction.TransactionExecutor.executeCallbacks (TransactionExecutor.java:108)
 
  at android.app.servertransaction.TransactionExecutor.execute (TransactionExecutor.java:68)
 
  at android.app.ActivityThread$H.handleMessage (ActivityThread.java:1955)
 
  at android.os.Handler.dispatchMessage (Handler.java:106)
 
  at android.os.Looper.loop (Looper.java:214)
 
  at android.app.ActivityThread.main (ActivityThread.java:7073)
 
  at java.lang.reflect.Method.invoke (Native Method)
 
  at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run (RuntimeInit.java:493)
 
  at com.android.internal.os.ZygoteInit.main (ZygoteInit.java:965)
Caused by: java.lang.IllegalStateException:
 
  at android.app.ContextImpl.startServiceCommon (ContextImpl.java:1666)
 
  at android.app.ContextImpl.startService (ContextImpl.java:1611)
 
  at android.content.ContextWrapper.startService (ContextWrapper.java:677)
 
  at anywheresoftware.b4a.keywords.Common.StartService (Common.java:884)
 
  at anywheresoftware.b4a.objects.ServiceHelper$StarterHelper.startFromActivity (ServiceHelper.java:184)
 
  at gd.tempomaster_pro.main.onCreate (main.java:64)
 
  at android.app.Activity.performCreate (Activity.java:7327)
 
  at android.app.Activity.performCreate (Activity.java:7318)
 
  at android.app.Instrumentation.callActivityOnCreate (Instrumentation.java:1275)
 
  at android.app.ActivityThread.performLaunchActivity (ActivityThread.java:3095)

The version released in the Play store was still compiled with B4A before version 9.0


Best regards,
Gunnar
 

Attachments

  • error.jpg
    error.jpg
    216.2 KB · Views: 367

Tempomaster

Active Member
Licensed User
Longtime User
Thank you for your fast reaction.:)

B4X:
        if (!includeTitle) {
            this.getWindow().requestFeature(android.view.Window.FEATURE_NO_TITLE);
        }
        if (fullScreen) {
            getWindow().setFlags(android.view.WindowManager.LayoutParams.FLAG_FULLSCREEN,   
                    android.view.WindowManager.LayoutParams.FLAG_FULLSCREEN);
        }
        
        processBA.sharedProcessBA.activityBA = null;
        layout = new BALayout(this);
        setContentView(layout);
        afterFirstLayout = false;
        WaitForLayout wl = new WaitForLayout();
        
        --- Zeile 64 ----
        if (anywheresoftware.b4a.objects.ServiceHelper.StarterHelper.startFromActivity(processBA, wl, false))
        --- Zeile 64 ----
        BA.handler.postDelayed(wl, 5);

    }

Best regards,
Gunnar
 
Upvote 0

Tempomaster

Active Member
Licensed User
Longtime User
Unfortunately, there is no information about the source code in the header of the code. Here again a slightly larger area of the Java code:

B4X:
public class main extends Activity implements B4AActivity{
    public static main mostCurrent;
    static boolean afterFirstLayout;
    static boolean isFirst = true;
    private static boolean processGlobalsRun = false;
    BALayout layout;
    public static BA processBA;
    BA activityBA;
    ActivityWrapper _activity;
    java.util.ArrayList<B4AMenuItem> menuItems;
    public static final boolean fullScreen = true;
    public static final boolean includeTitle = false;
    public static WeakReference<Activity> previousOne;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        mostCurrent = this;
        if (processBA == null) {
            processBA = new BA(this.getApplicationContext(), null, null, "gd.tempomaster_pro", "gd.tempomaster_pro.main");
            processBA.loadHtSubs(this.getClass());
            float deviceScale = getApplicationContext().getResources().getDisplayMetrics().density;
            BALayout.setDeviceScale(deviceScale);
            
        }
        else if (previousOne != null) {
            Activity p = previousOne.get();
            if (p != null && p != this) {
                BA.LogInfo("Killing previous instance (main).");
                p.finish();
            }
        }
        processBA.setActivityPaused(true);
        processBA.runHook("oncreate", this, null);
        if (!includeTitle) {
            this.getWindow().requestFeature(android.view.Window.FEATURE_NO_TITLE);
        }
        if (fullScreen) {
            getWindow().setFlags(android.view.WindowManager.LayoutParams.FLAG_FULLSCREEN,   
                    android.view.WindowManager.LayoutParams.FLAG_FULLSCREEN);
        }
        
        processBA.sharedProcessBA.activityBA = null;
        layout = new BALayout(this);
        setContentView(layout);
        afterFirstLayout = false;
        WaitForLayout wl = new WaitForLayout();

        --- line 64: ---
       if (anywheresoftware.b4a.objects.ServiceHelper.StarterHelper.startFromActivity(processBA, wl, false))
        --- line 64: ---    

        BA.handler.postDelayed(wl, 5);

    }
    static class WaitForLayout implements Runnable {
        public void run() {
            if (afterFirstLayout)
                return;
            if (mostCurrent == null)
                return;
            
            if (mostCurrent.layout.getWidth() == 0) {
                BA.handler.postDelayed(this, 5);
                return;
            }
            mostCurrent.layout.getLayoutParams().height = mostCurrent.layout.getHeight();
            mostCurrent.layout.getLayoutParams().width = mostCurrent.layout.getWidth();
            afterFirstLayout = true;
            mostCurrent.afterFirstLayout();
        }
    }
    private void afterFirstLayout() {
        if (this != mostCurrent)
            return;
        activityBA = new BA(this, layout, processBA, "gd.tempomaster_pro", "gd.tempomaster_pro.main");
        
        processBA.sharedProcessBA.activityBA = new java.lang.ref.WeakReference<BA>(activityBA);
        anywheresoftware.b4a.objects.ViewWrapper.lastId = 0;
        _activity = new ActivityWrapper(activityBA, "activity");
        anywheresoftware.b4a.Msgbox.isDismissing = false;
        if (BA.isShellModeRuntimeCheck(processBA)) {
            if (isFirst)
                processBA.raiseEvent2(null, true, "SHELL", false);
            processBA.raiseEvent2(null, true, "CREATE", true, "gd.tempomaster_pro.main", processBA, activityBA, _activity, anywheresoftware.b4a.keywords.Common.Density, mostCurrent);
            _activity.reinitializeForShell(activityBA, "activity");
        }
        initializeProcessGlobals();       
        initializeGlobals();
        
        BA.LogInfo("** Activity (main) Create, isFirst = " + isFirst + " **");
        processBA.raiseEvent2(null, true, "activity_create", false, isFirst);
        isFirst = false;
        if (this != mostCurrent)
            return;
        processBA.setActivityPaused(false);
        BA.LogInfo("** Activity (main) Resume **");
        processBA.raiseEvent(null, "activity_resume");
        if (android.os.Build.VERSION.SDK_INT >= 11) {
            try {
                android.app.Activity.class.getMethod("invalidateOptionsMenu").invoke(this,(Object[]) null);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }

Best regars,
Gunnar
 
Upvote 0

Tempomaster

Active Member
Licensed User
Longtime User
B4X:
Sub Activity_Create(FirstTime As Boolean)
    Dim TextReader1 As TextReader
    Dim TextWriter1 As TextWriter
    Dim line As String
    
    InitializeLanguage
    
    dbname="TempoMaster"
    inifolder = File.DirInternal & "/" & dbname
    
    allgpxfiles.Initialize
    btfunktion="0"
    splashhome=0
    
    Try
        If ConnectedDeviceName<>"" Then
            Dim result As Int
            Dim btgeraet As String
            
            If File.Exists(inifolder, "bt.ini")=True Then
                TextReader1.Initialize(File.OpenInput(inifolder, "bt.ini"))
                Do While line <> Null
                    line = TextReader1.ReadLine
                    If line=Null Then
                        btfunktion="0"
                        Exit
                    End If
                    btgeraet=SF.SplitGetWord(line,";",1)
                    btfunktion=SF.SplitGetWord(line,";",2)
                    If btgeraet=ConnectedDeviceName Then
                        Exit
                    End If
                Loop
                TextReader1.Close
            End If
            
            If btfunktion="0" Then
                '920=Tempomaster bei Verbindung mit diesem Gerät automatisch starten?
                '921=Immer
                '922=Nie
                result=Msgbox2(trans.GetText("920"), ConnectedDeviceName, trans.GetText("921"), "", trans.GetText("922"), Null)

                If result = DialogResponse.NEGATIVE Then
                    TextWriter1.Initialize(File.OpenOutput(inifolder, "bt.ini", True))
                    line=ConnectedDeviceName & ";" & "2"
                    TextWriter1.WriteLine(line)
                    TextWriter1.Close
                    btfunktion="-1"
                    Return
                Else If result = DialogResponse.CANCEL Then
                    btfunktion="-1"
                    Return
                Else If result = DialogResponse.POSITIVE Then
                    TextWriter1.Initialize(File.OpenOutput(inifolder, "bt.ini", True))
                    line=ConnectedDeviceName & ";" & "1"
                    TextWriter1.WriteLine(line)
                    TextWriter1.Close
                    deviceverbindung=ConnectedDeviceName
                End If
            Else If btfunktion="1" Then
                'Tempomaster startet
                deviceverbindung=ConnectedDeviceName
            Else If btfunktion="2" Then
                btfunktion="-1"
                Return
            End If
        End If
    Catch
        ConnectedDeviceName=""
    End Try
    
    If FirstTime=True Then
        gpsberech=False
        
        If File.IsDirectory(File.DirInternal,dbname) = False Then
            File.MakeDir(File.DirInternal, dbname)
        End If
        If File.Exists(inifolder, "tempomaster.ini")=False Then
            File.Copy(File.DirAssets, "tempomaster.ini", inifolder, "tempomaster.ini")
        End If
        
        TextReader1.Initialize(File.OpenInput(inifolder, "tempomaster.ini"))
        Do While line <> Null
            line = TextReader1.ReadLine
            If line<>Null Then
                multivar=line
            End If
        Loop
        TextReader1.Close
        
        audiober=multilesen(43)
        
        oauth2.Initialize(Me, "oauth2", ClientId, "https://www.googleapis.com/auth/gmail.send")
        warteschleife=True
        
        If audiober="0" Then
            '81=Mikrofon Berechtigung ist optional. Zur nachträglichen Aktivierung die App entfernen und wieder neu installieren.\n\nDie anderen Berechtigungen sind für die Funktion der App alle erforderlich.
            Msgbox(trans.GetText("81"),"Info")
            audiober="1"
        End If

        If OP.RequestPermission("OP") Then
            'A permission to draw overlays over applications is required
            Wait For OP_DrawPermission(Allowed As Boolean)
        End If
        
        If OP.IsAllowed=False Then
            Activity.RemoveAllViews
            Activity.Finish
            ExitApplication
        End If
        
        Starter.Rp.CheckAndRequest(Starter.Rp.PERMISSION_WRITE_EXTERNAL_STORAGE)

        audioerlaubt=False
        Starter.rp.CheckAndRequest(Starter.rp.PERMISSION_RECORD_AUDIO)
    End If
End Sub

Sub InitializeLanguage
   locale.Initialize
   If locale.Language = "de" Then
       trans.Initialize2(File.DirAssets, "tempomaster", "de") 'ignore
   Else
       If File.Exists(File.DirAssets, "tempomaster_" & locale.Language & ".lng") = True Then
           trans.Initialize2(File.DirAssets, "tempomaster", locale.Language) 'ignore
       Else
           trans.Initialize2(File.DirAssets, "tempomaster", "en") 'ignore
       End If
   End If
End Sub
 
Upvote 0

Tempomaster

Active Member
Licensed User
Longtime User
The problem is with Android 9 devices but not generally. I have a lot of feedback that the app runs perfectly on Android 9.
 
Upvote 0

Tempomaster

Active Member
Licensed User
Longtime User
I thank you first. I will try my luck.

I have no understanding for errors that occur with newer operating system versions. Someone (at the manufacturer of the operating system) was working sloppily.

Best regards,
Gunnar
 
Upvote 0
Top