Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Post
  • Reply
rotaryfun
Jun 30, 2008

you can be my wingman anytime
I've not found an elegant solution for including a populated database with an app. Anyone have any experience or do you always check for a database and create it on a first run?

Adbot
ADBOT LOVES YOU

rotaryfun
Jun 30, 2008

you can be my wingman anytime
So I have my first app that I'm building and I've run into a asynctask issue in that I think I need to use it but I don't know just how to do it.

I have a doFirstRun method that is called and run if a setting isn't found in the sharedprefs
code:
private void doFirstRun() {
   SharedPreferences settings = getSharedPreferences("PREFS", MODE_PRIVATE);
   if (settings.getBoolean("isFirstRun", true)) {
      Toast.makeText(this, "first run: \ncreating player database and adding players", Toast.LENGTH_SHORT).show();
       addPlayers();
       SharedPreferences.Editor editor = settings.edit();
       editor.putBoolean("isFirstRun", false);
       editor.commit();
   }
}
It displays the toast message and runs another method to add players to a database.

However, the message is never really displayed and it hangs while adding them.

The way they are added is by passing player information to a object method... 150 of them. This hangs the app for a few seconds until that is finished.
example:
code:
datasource.createPlayer("player", 10, 1, 1, 1, 5, 4, 8);
How can I make this smoother? I tried following this guys example but wasn't successful.
http://labs.makemachine.net/2010/05/android-asynctask-example/

rotaryfun
Jun 30, 2008

you can be my wingman anytime

Doctor w-rw-rw- posted:

Shouldn't the progressdialog be a member of the asynctask and be started in onPreExecute?

I'm getting:
Type mismatch: cannot convert from void to ProgressDialog

Would this be why?

edit:
I changed it to
code:
protected void onPreExecute() {
   progress = ProgressDialog.show(this, "First Run", "Creating player database and adding players").show();
}
Now I'm getting:
The method show(Context, CharSequence, CharSequence) in the type ProgressDialog is not applicable for the arguments (ViewPlayers.AddPlayersTask, String, String)

edit2:
Nevermind, I added changed the context from this to ViewPlayers.this (activity name) and it cleared the error.

edit3:
Got it all up and running. Works great. Thanks for the code help gentlemen!

rotaryfun fucked around with this message at 18:30 on Aug 10, 2012

rotaryfun
Jun 30, 2008

you can be my wingman anytime

Doctor w-rw-rw- posted:

:stonk: are you not using an IDE to edit? You should be able to autocomplete most of that in seconds.

Yeah I'm using Eclipse but for whatever reason it autocompleted to just this

rotaryfun
Jun 30, 2008

you can be my wingman anytime
That's odd. Doesn't the resource class get built during compile?

  • 1
  • 2
  • 3
  • 4
  • 5
  • Post
  • Reply