• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

ActivityMain simple question

 
Greenhorn
Posts: 11
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Is it common to leave Activity Name set to the default MainActivity when creating a new project vs something more descriptive like MyAppMainActivity or MyAppStart ect...
 
Saloon Keeper
Posts: 7601
177
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
To be honest, MainActivity is not really less descriptive than the other ones you propose :-). Leaving it at that at least indicates which activity is run when the app is started, so I think it's fine.
 
Ranch Hand
Posts: 607
11
Android Python Open BSD VI Editor Slackware
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Chad McAte wrote:Is it common to leave Activity Name set to the default MainActivity when creating a new project vs something more descriptive like MyAppMainActivity or MyAppStart ect...


I would leave as `MainActivity`
 
Giovanni Montano
Ranch Hand
Posts: 607
11
Android Python Open BSD VI Editor Slackware
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I pressed too soon.

The point is that MainActivity is the best name because you are going to write no more than a dozens of rows.
First of all people use a lot

Fragment

and you can  apply there a distintive way to call it FeatureBlaBlaFragment.
Then you are going to use packages, this tremendously helps to maintain the code clean
Then you are going to give the possibility to somebody that inspects your code to skip the

AndroidManifest.xml

.
In Java you use
, so in Android( that should be as best practice more considered Kotlin than Java today) is better to have MainActivity with a small

@Override onCreate

 in Java or better
in Koltin
    that can be easily found with IntelliJ double tab( the search function) rather than typing AndroidManifest and looking into the file for the rows and then switch to the MainActivity

<activity
           android:name="com.example.android.main.MainActivity"
           android:label="@string/app_name"
           android:launchMode="singleTop">
           <intent-filter>
               <action android:name="android.intent.action.MAIN" />
               <category android:name="android.intent.category.LAUNCHER" />
           </intent-filter>
       </activity>


Because 99 per cent of the time there will be a MainActivity.kt into the src package

Last point. Beginners in Android are usually afraid to maintain MainActivity with the name because clashes with the so called

Single Responsibility Principle

that states that every class should do only one thing.
Instead the have the so called big ball of mud namely an Activity that does everything. But when you have only a MainActivity.kt with only a dozen of rows, it remains a MainActivity.kt and you are not afraid to call it in this way, at the opposite it is making clear where your program instructions starts( even if this is improper in compiling terms) . Here it is a MainActivity the way a recruiter would be hopefully/ possibly favorable impressed to see it


Happy Coding
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic