0

When my program start I would like to do some settings before is really starting. Forexample choose the user, check the updates and so on. After these settings I would like to start the main program with the appropriate.

Which is the best way to do this?

meklod400
  • 129
  • 1
  • 2
  • 12

2 Answers2

0

You can run an AyncTask, or multiple if you need one for each check, in your onCreate() and show a ProgressDialog while the data is being fetched then cancel it in onPostExecute() and move on to the rest of the MainActivity depending on the data that is downloaded. If you need help getting started with AsyncTask you can see this SO answer on the basic structure.

If you use a ProgressDialog then the app will still start but the users will see something and know that data is loading so they won't feel like it is freezing or taking too long to load (or at least they will know why it isn't loaded right away).

AsyncTask Docs

Edit after comment

For what you said you want in your comment you can do this easily with an Activity that has a Dialog Theme. This will give you the functionality you need (a couple Buttons and store the values) but it will look like a little popup. You can't use an actual Dialog as they need an Activity, the same with any menus, AFAIK. Just create your Activity and make it the launcher and main using the Intent-filters then also add the following line to that Activity's tag in the manifest

android:theme="@android:style/Theme.Dialog"

This approach should give you what you need

Community
  • 1
  • 1
codeMagic
  • 44,549
  • 13
  • 77
  • 93
  • I need a simple popup menu which start at first before the main program and I can choose 1. or 2. if I choose the 1 then the store variable will countain the 1 value if i choose the 2. then the 2... – meklod400 Jul 01 '13 at 20:45
  • @meklod400 see my edit. I think this should give you what you need – codeMagic Jul 01 '13 at 20:50
  • Yeah looks great maybe could you show me some example? Cause Really hard to find working solutions? Really thank u! – meklod400 Jul 01 '13 at 23:05
  • I'm not really sure what kind of an example you want me to give you. I don't mind but without seeing something you have tried its hard to say. I don't know exactly what you want. If you need a couple `Buttons`, `Spinner`, EditText`, etc... You just build the `layout` and an `Activity` doing what you want then use the code above to make it look like a `Dialog` – codeMagic Jul 01 '13 at 23:22
  • Kind of example which is start with a function call and show two button – meklod400 Jul 02 '13 at 07:36
  • Just create a layout file with the `Buttons` you want and use `setContentView()` in `onCreate()` just like normal then have your `Buttons` do whatever you want – codeMagic Jul 02 '13 at 13:17
0

There are numerous ways to do that.

First - your app is doing some heavy stuff and this may be freezing user interface. In that version do: 1. Create and activity on what you will override onCreate method and set some content with a spinner - so something will be alive and user will see that something is being done. 2. after you will compute all the things that your app need and may I suggest write it to some global variables override onStart method in what change layout to what suit you and give a user a great UI!

Second - you app is not heavy lifting here just throw everything into override of onStart method.

Handy material here for educating: enter image description here

Mateusz Zając
  • 316
  • 5
  • 19