Search code examples
javaandroidandroid-studioadb

Run app from Android Studio not working on device, OK on emulator


I have an app which is basically a WebView of a web app I run.

I created the app initially with just one activity (activity_main) that contained the WebView and have been playing around getting that to work as required.

I then decided to add a second activity to do some pre-load checks such as checking for an active network connection etc.

When I added this pre-load-checks activity everything seemed to be going OK but when the app ran in the emulator or on my device (installing the apk or running via AS on the device), my new pre-load-checks activity was the one that started. This was OK as I was tweaking the layout and graphics etc.

I haven't finished writing pre_load_checks yet, so it doesn't yet do all of its checks and doesn't launch the second activity, BUT I need to do some more work on the WebView.

So, I tried switching the app to launch the activity_main activity on launch by changing the Launch Options in Run/Debug Configurations.

Now when I try to run the app on my device it fails. Sometimes it just doesn't start, sometimes I get a message saying that my app has stopped. It works OK in the emulator though.

Note that I hadn't changed anything in activity_main at this point.

When I try to run it, the messages in AS say that the app has been launched on my device - no errors.

I then decided to try renaming the activity_main activity to something more sensible seeing as it was no longer going to be the startup activity. I renamed it to activity_website_view via the refactor->rename option for the layout xml. I also did the same for the associated java file.

After a bit of cleaning up I managed to get things to compile again but somewhere along the line something else odd has happened - now if I go into the Run/Debug Configurations screen my newly renamed activity_website_view shows up under the 'Applications branch of the tree along with app. My pre_load_checks activity doesn't show here.

Similarly, in the toolbar drop down that lets you choose what to run/debug, I have the option to run app or activity_website_view, but not pre_load_checks.

Are these related or is it correct that I have direct access to one of the activities? I can see that I can manually add another 'application' to the list, but I wonder if something I have done along the way has caused my old activty_main to be added automatically and if this is related to why that activity will no longer run on my device but is OK on the emulator.

For info my AndroidManifest.xml is below:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.nooriginalthought.bluebadgeparking">

    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />

    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:supportsRtl="true"
        android:theme="@style/AppTheme">
        <activity android:name=".PreLoadChecks"
            android:theme="@style/AppTheme.NoActionBar">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <activity
            android:name=".websiteViewActivity"
            android:configChanges="orientation|screenSize|keyboard|keyboardHidden"
            android:label="@string/app_name"
            android:theme="@style/AppTheme.NoActionBar">
            <intent-filter>
                <paction android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>

</manifest>

Solution

  • As per my comment above, this was a typo.

    The 'p' in front of action shouldn't have been there and was stopping things from launching on my device - BUT very oddly it didn't stop them running in the emulator.