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 badges1 Answer
Reset to default 0Without 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
版权声明:本文标题:android - Cannot start Flutter MainActivity from AndroidAuto service - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736556814a1944590.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论