1

Is it possible through android Manifest file to put some sort of condition which invokes different activity as main activity of the app based on underlying android platform ?

In my case I want a different main activity for API-8 to 11 and from 11 onwards I want a different activity as main activity.

So I am using following code right now in the android manifest file

    <activity
        android:name="myapp.org.MainActivity"          
        android:screenOrientation="portrait" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>

Please advise, I have an app whose 5-10 % users are still on platform 2.2 and 2.3 and it is too much of a pain to keep supporting old platforms.

Please advise,

thanks, Ahmed

Explanation Why I want to do it:

The application foot print is small only 0.6 MB only, My plan was to copy entire code and enhance it for newer versions which will probably double the foot print. then based on platform launch appropriate mainactivity and if platform is newer mainactivity from newer part of code will execute and legacy code will never get a chance to execute (I believe) and vice versa,

The only flaw I could think of is if the android system somehow instantiates classes directly which probably only happens if I declare a broadcast receiver in the manifest, which I don't .. so I was hoping it is safe to publish single binary to all users and at runtime suitable code will execute. The legacy code will be thrown away from the main binary as the number of users drop further.

All the code is in project which is android library and the main app is a stub which uses the library and if I realise the scenario I have painted above, I will have two android libraries, one legacy one and new.

Ahmed
  • 14,503
  • 22
  • 92
  • 150

4 Answers4

2

Maybe you can add a new LauncherActivitiy to judge API level, then navigate to different MainAcivity base on the API Level.

jobcrazy
  • 1,073
  • 10
  • 16
0

There is a better Idea, in the main activity add a condition in onCreate that gets the API version and if it's froyo for example finish this activity and start another one else continue using this activity. here you are a link showing how to get the API: Retrieving Android API version programmatically

Community
  • 1
  • 1
SaNtoRiaN
  • 2,212
  • 2
  • 15
  • 25
0

if it is just for the main activity, this solution might be a little bit too much and you should use one of the other solutions, but if you want to separate your whole application by the API level i recommend the Multiple APK Support of Android.

Rich
  • 1,015
  • 1
  • 10
  • 22
  • Thanks for giving a different solution, I have updated my question by adding an explanatory paragraph as to what I had in my mind, please have a look.. – Ahmed Aug 05 '15 at 20:19
  • I saw the article it mentions you should only go for multiple apks if your app has larger footprint 50MB or more, mine is only 0.6 MB – Ahmed Aug 05 '15 at 20:22
0

If you are developing on Android Studio, look at gradle flavors, they allow you to do compile a different main activity for every platform, have a different set of resourses, icons, strings etc.

Michael P
  • 2,017
  • 3
  • 25
  • 33