admin管理员组

文章数量:1123232

I have made a Flutter app for Android Auto which displays a diagram on the phone screen and then also displays the same diagram on the AA screen in the car. It has a standard Flutter MainActivity, and a service provided by me. If I tap the icon on the phone, Android starts both the activity and the service. But if I start the app from the car display, AA only starts the service. To fix this I tried to start MainActiviy from the service. In the CarHomeScreen init() function I have

        val appContext = carContext.applicationContext
        val intent2 = Intent(appContext, MainActivity::class.java)
        intent2.action = Intent.ACTION_MAIN
        intent2.addCategory("android.intent.category.CAR_LAUNCHER")
        intent2.flags = Intent.FLAG_ACTIVITY_NEW_TASK
        appContext.startActivity(intent2)
        Log.d("CarHomeScreen", "MainActivity intent launched")

In the manifest, I have the Flutter standard lines

            <activity
                android:name=".MainActivity"
                android:exported="true"
                android:launchMode="singleTop"
                android:taskAffinity=""
                android:theme="@style/LaunchTheme"
                android:configChanges= etc...
                android:hardwareAccelerated="true"
                android:windowSoftInputMode="adjustResize">
            <meta-data
              android:name="io.flutter.embedding.android.NormalTheme"
              android:resource="@style/NormalTheme"
              />
            <intent-filter>
                <action android:name="android.intent.action.MAIN"/>
                <category android:name="android.intent.category.LAUNCHER"/>
            </intent-filter>
        </activity>

The Logcat shows the message, but MainActiviy is not launched. What am I doing wrong? (I have asked both Claude and Gemini for help and got loads of useless sugesstions. Hope some human out there can help!)

I have made a Flutter app for Android Auto which displays a diagram on the phone screen and then also displays the same diagram on the AA screen in the car. It has a standard Flutter MainActivity, and a service provided by me. If I tap the icon on the phone, Android starts both the activity and the service. But if I start the app from the car display, AA only starts the service. To fix this I tried to start MainActiviy from the service. In the CarHomeScreen init() function I have

        val appContext = carContext.applicationContext
        val intent2 = Intent(appContext, MainActivity::class.java)
        intent2.action = Intent.ACTION_MAIN
        intent2.addCategory("android.intent.category.CAR_LAUNCHER")
        intent2.flags = Intent.FLAG_ACTIVITY_NEW_TASK
        appContext.startActivity(intent2)
        Log.d("CarHomeScreen", "MainActivity intent launched")

In the manifest, I have the Flutter standard lines

            <activity
                android:name=".MainActivity"
                android:exported="true"
                android:launchMode="singleTop"
                android:taskAffinity=""
                android:theme="@style/LaunchTheme"
                android:configChanges= etc...
                android:hardwareAccelerated="true"
                android:windowSoftInputMode="adjustResize">
            <meta-data
              android:name="io.flutter.embedding.android.NormalTheme"
              android:resource="@style/NormalTheme"
              />
            <intent-filter>
                <action android:name="android.intent.action.MAIN"/>
                <category android:name="android.intent.category.LAUNCHER"/>
            </intent-filter>
        </activity>

The Logcat shows the message, but MainActiviy is not launched. What am I doing wrong? (I have asked both Claude and Gemini for help and got loads of useless sugesstions. Hope some human out there can help!)

Share Improve this question asked 9 hours ago Bo HellgrenBo Hellgren 1811 silver badge12 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 0

Without logs, my best guess would be that you're running into some of the restrictions on background activity launching.

本文标签: androidCannot start Flutter MainActivity from AndroidAuto serviceStack Overflow