Search code examples
javaandroidandroid-studiowear-os

Wear OS App denied for crash on startup - Multiple Activities


Summary

When building a wear OS app with multiple activities, you may end up with an improper project structure. To add activities to my app, I right clicked my com.example.thing folder>new>activity>blank wear activity. This will setup a new java or kotlin file, and a layout XML file for you. Quite convenient. What this DOESN'T do however, is configure your AndroidManifest.xml properly.

During testing, everything will appear to work fine, especially if you only test on an emulator. However, due to the way the AndroidManifest is automagically setup, it will add all activities with the following intent filters:

<action android:name="android.intent.action.MAIN" />            
<category android:name="android.intent.category.LAUNCHER" />

This creates a problem as installing the APK will result in you having X amount of your app loaded into the device, where X is the amount of activities you created. For example, I had a login activity, a main activity, and a settings activity. When running the app, I ended up with 3 apps in my app list, each named accordingly.


Solution

  • To fix this, simply remove the intent filters for all but one of your activities, leaving the one for whichever you want your main startup activity to be. Of course, for more complex apps, you may want to change your intent filters, rather than remove them. You can read all about them here:

    https://developer.android.com/guide/components/intents-filters