Note that there are some explanatory texts on larger screens.

plurals
  1. POWhere/how to implement SQLiteDatabase and AsyncTask in TabActivity
    text
    copied!<p>I'm basically finished an application I'm developing (my very first!), except for implementing any data saving mechanism. I looked into the options a while ago and decided the SQLiteDatabase is the best to go with, but it was difficult to wrap my head around how exactly to implement it, so I left it until I finished the rest of the program. Since then I've just been testing it by re-entering all the values each time I run it on my device.</p> <p>The app starts with basically nothing on the screen. The user adds players (via the menu and a Dialog). Once the player list is finalized, the user clicks "save" in the Dialog. Then a Table Row for each player dynamically inflates and includes a Button, a few ImageViews, and a TextView, all displaying various attributes of each Player. That doesn't really matter for my question.</p> <p>So, my application will basically just keep track of Player objects. I have the database object all built using this as a guide: <a href="http://www.androidhive.info/2011/11/android-sqlite-database-tutorial/" rel="nofollow">http://www.androidhive.info/2011/11/android-sqlite-database-tutorial/</a>, swapping "contacts" for "players" for the most part.</p> <p>What I have trouble understanding is where exactly to implement the "saving" and "loading" of each player object, as well as what to do in the main Activity's onCreate, onResume, and onStop methods. I've been looking into this for many hours now, and I've learned I should also implement an AsyncTask, but that is even more complicated and I can't even get the basic data loading into my brain, let alone doing it asynchronously.</p> <p>There's a good example of how to implement both AsyncTask and SQLiteDatabase in a book I'm reading called "Android for Programmers: An App-Driven Approach" in the Deitel Developer Series, but in their example they use a CursorAdapter in a ListActivity, so I don't know how to make it apply for my situation. (Mine is a TabActivity, what I explained above is just for a "View Players" Tab.) </p> <p>It makes sense to me to add Players to the database when the user clicks "save" in the "Add Players Dialog," but I don't understand where to reload the Player objects as well as where to reinflate each Player's table row. </p> <p>I'm sorry I am not posting code to be more precise but it's more of a general question and I'd rather not post my entire app since it's about a thousand lines long. Any help would be greatly appreciated, I try not to post every little thing on here but this stuff has frustrated me too long!</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload