Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error while Launching activity

Tags:

I recently downloaded Android Studio 2.0 and create a new startup app and did not add anything code by myself. After running the app, android studio installs the APK on emulator successfully but does not launch the app instead it gives the following error:

$ adb shell am start -n "com.example.muhammad.firstapp/com.example.muhammad.firstapp.MainActivity" -a android.intent.action.MAIN -c android.intent.category.LAUNCHER

Unexpected error while executing: am start -n "com.example.muhammad.firstapp/com.example.muhammad.firstapp.MainActivity" -a android.intent.action.MAIN -c android.intent.category.LAUNCHER

Error while Launching activity

I searched it on google and found that it was asked before but the provided solution isn't working for me either. I also did not add anything in the AndroidManifest.xml file.

AndroidManifest.xml

<?xml version="1.0" encoding="utf-8"?>
    <manifest xmlns:android="http://schemas.android.com/apk/res/android"
        package="com.example.muhammad.firstapp">
        <application
            android:allowBackup="true"
            android:icon="@mipmap/ic_launcher"
            android:label="@string/app_name"
            android:supportsRtl="true"
            android:theme="@style/AppTheme">
            <activity android:name=".MainActivity">
                <intent-filter>
                    <action android:name="android.intent.action.MAIN" />
                    <category android:name="android.intent.category.LAUNCHER" />
                </intent-filter>
            </activity>
        </application>
    </manifest>

MainActivity.java

package com.example.muhammad.firstapp;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;

public class MainActivity extends AppCompatActivity {
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
    }
}

activity_main.xml

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context="com.example.muhammad.firstapp.MainActivity">

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Hello World!" />
</RelativeLayout>
like image 491
metior Avatar asked Apr 22 '16 20:04

metior


People also ask

What does launcher activity mean?

Launcher Activities are the activities that can be launched for a given intent. For example, when you press an app icon on the home screen, the StartActivity intent starts the activity you have specified as the launcher activity.

What is launch activity android?

Launch mode is an instruction for Android OS which specifies how the activity should be launched. It instructs how any new activity should be associated with the current task.


2 Answers

I had exactly this same problem today [Android Studio 2.3.3, Android 8.0 on the phone]

This is what I discovered. The app that I was trying to install was not shown in the android Application window [the one where you have them all]. But once I went in: Settings->Apps&Notifications->AppInfo I could see this screenshot where it was said that this app was "not installed for this user":

enter image description here

At that point I entered the app->clicked on the three points in the top right corner->Uninstall for all the users

Now when I tried to run the project through Android Studio the error message disappeared and the app was correctly installed

Hope this helps, have a good day
Antonino

like image 89
Antonino Avatar answered Oct 07 '22 19:10

Antonino


If you are using android 2.0+, take the following steps
1. Go to run
2. Select edit configurations..
3. type -r in the Install Flags text field
4. Apply and Ok then run program again

tested(23/07/2016)

like image 21
Root Avatar answered Oct 07 '22 21:10

Root