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>
I tried almost every solution found in the community, but the Error Launching activity never gone. Now I found what's the reason of my case.
I use a USB connected LG K20 Plus phone to test my projects built on the Android Studio 2.3.3, the Error Launching activity will appear if I uninstall the project in the phone, it will launch normally again if the deleted project is reinstalled.
I hope this will help people having the same or similar Error in your developing projects.
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)
There is issue with studio 2.0+ instant run feature
Work around provided at Android Open Source Project - Issue Tracker
Don't waste time in re installation of studio or cleaning gradle build file often .
Just add -r flag in Install flags in Run->Edit configurations->General
Though I'm not sure about the exact reason for this problem, I just found a solution when I cleaned the project. So, go to
Build -> Clean project
. This should help youIn my experience this error occurs when you manually uninstall your apk when it's building or installing via android studio.
In a such case I simply create a apk and install it on the AVD or phone. After It will work as usual.
Hope this will help to someone.
I encounter the same problem in AVD, when first start app it was fine but when launch the app again it reports "Error while Launching activity".
My resolution is: in AVD, uninstall the apk, maybe the reason is the new Android studio has an issue when install apk to a AVD.
Thanks, Yu