Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Must the main activity name be .MainActivity?

My app has this main activity:

<activity
    android:name=".main.MainActivity"
    ...
    <intent-filter>
        <action android:name="android.intent.action.MAIN" />
        <category android:name="android.intent.category.LAUNCHER" />
    </intent-filter>
</activity>

and it launches with no problem from the home launcher. However, when I try to launch it from Google's Gesture Search, I get a Gesture error message saying that the app does not have .MainActivity.

https://play.google.com/store/apps/details?id=com.google.android.apps.gesturesearch

Do Android apps required to have the main activity called .MainActivity? If not, is it a soft recommendation or a convention or just a bad assumption on Gesture's part?

like image 393
user1139880 Avatar asked May 28 '12 04:05

user1139880


People also ask

Can we change the name of main activity in android?

Yes, you can change the name of MainActivity by, opening the directory of the java file in android studio, right-click on it and find refactor, then rename, put in the name you like then click on refactor. Save this answer.

What is the main activity?

Typically, one activity in an app is specified as the main activity, which is the first screen to appear when the user launches the app. Each activity can then start another activity in order to perform different actions.

What is main activity XML?

The activity is a Java class, and the layout is an XML file, so the names we've given here will create a Java class file called MainActivity. java and an XML file called activity_main. xml. When you click on the Finish button, Android Studio will build your app.

How do you make an activity the main activity?

Navigate to app>java>your app's package name>Right click on it>New>Empty activity and name it as MainActivity2. Navigate to app>res>layout>activity_main2. xml and add the below code to it. Comments are added in the code to get to know in detail.


2 Answers

Android apps do not require any activity called .MainActivity. Furthermore, I'm not aware of any conventions like this. It sounds like you may be unknowingly telling Gesture that you want something called .MainActivity.

Perhaps it is because you put a package name before the actual name of the class. Try putting the fully qualified class name instead. Also try renaming the Activity, and see if you get any different results.

like image 165
gobernador Avatar answered Nov 09 '22 23:11

gobernador


Android apps do not require an activity named MainActivity and you should not assume (and should certainly not rely) on any application implementing one.

Furthermore, I have never heard of any convention that recommends doing so. Most developers will name each activity to suit its behavior and/or purpose in the application.

like image 38
Alex Lockwood Avatar answered Nov 10 '22 00:11

Alex Lockwood