-1

I need the user of my app to be able to select what Activity to launch when the app starts. Each user may have a different activity they need the most and I want it to be configurable by the user. I have searched on Google for how to do this and have not been able to find a solution.

Can anyone help me with this issue?

Nicholas Hall
  • 161
  • 13
Asif Mushtaq
  • 3,658
  • 4
  • 44
  • 80
  • If you read the other question these appear to be different. I believe what they want in this case is to allow the user of the app to specify what activity they want to have the app launch upon starting the app. The other question is regarding the developer changing what activity the app will launch upon starting. – Nicholas Hall May 07 '15 at 21:32
  • I mean each app user can change default activity on their requirement..!! – Asif Mushtaq May 08 '15 at 05:22

2 Answers2

0

You absolutely can do this, but I will keep my solution generic so you can implement it in various different ways.

First you will need to have a storage location where you store what activity the user has selected to launch into. You can implement this using various ways, probably the quickest would be to store it in SharedPreferences, but if you have a database already you could also store it inside your database.

Second you will need a method for the user to specify which activity they want to launch into. This could be a Setting Activity or even a means of selecting the current activity as the default.

Once you have all of this it is just a matter of putting the pieces together. You will want a new activity, LauncherActivity, this will be what you configure to be the main activity in AndroidManifest. All this activity will do, other than possibly display a splash screen, is retrieve the stored activity class with a default to fall back on, and launch the intent to start the actual desired activity. Make sure you call finish() on the LauncherActivity after you have launched the intent.

Nicholas Hall
  • 161
  • 13
0

In the manifest.xml file:

<activity android:name=".ActivityName" android:label="@string/app_name">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
</activity>

Note that it's necessary the android:name attribute of the <Activity> node should begin with a '.' and is just the name of the java file. For example, if your java file was named Website.java, then the android:name attribute would be:

android:name=".Website"
marc_s
  • 455
  • 1
  • 4
  • 15