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
A COMPUTER GUY
Aug 23, 2007

I can't spare this man - he fights.

Karthe posted:

Is a ContentProvider necessary when I'm just working with internal SQLite databases? I'm learning about them now and am left wondering if implementing one would be overkill; all I want to do is move database queries into a separate thread so the app won't hang. Right now I'm only querying static databases, though I will eventually implement another database that will be populated with user-generated content produced from within the app. I want to handle all of the database-related stuff in a database helper class, but everything I've read about introducing threading into the process points me to implementing a CP.

If ContentProviders are something I need to learn if I'm going to be working with SQLite, then can someone help me understand how to best craft URI's? I've skimmed a few ContentProvider tutorials and still can't wrap my head around how I'm supposed to craft URI's for my various use cases. I'm afraid I'll gently caress up and create a CP that's too limited in scope (or go the other way and set up too many URI's) and that'll force me to go back and rewrite large sections of code.

Nothing wrong with just calling rawQuery on a SQLiteDatabase object until you start to have more complex queries. The CommonsWare library is ace for asynchronous SQLite queries, but you may not actually need it.

Adbot
ADBOT LOVES YOU

A COMPUTER GUY
Aug 23, 2007

I can't spare this man - he fights.

Claeaus posted:

I've started looking into AsyncTask and planning on implementing it in my project. However, I would prefer if I could keep them separate from the rest of the code as I've got quite a nice MVC thing going on.

The problem is that I have some methods that are quite time consuming which makes it a bit hard to find a place to put the publishProcess() call.


For example:
code:
doInBackground()
{
    model.timeConsumingCalculations();
    publishProcess();
}
I don't like the idea of putting the AsyncTask inside the model as that would kind of mix it together with the UI I feel. Or should I use the Runnable class and make the model itself run on different threads or something. What would be a good way of solving this and keeping the different parts encapsulated?

Awhile ago on a project in school, one of my classmates did something like this:
code:
public class ExecuteOnBackgroundThreadTask extends AsyncTask<Void, Void, Void> {
  Runnable preExecute, inBackground, postExecute;
  Handler handler;

  public ExecuteOnBackgroundThreadTask(Runnable preExecute, Runnable inBackground, Runnable postExecute) {
    this.preExecute = preExecute;
    this.inBackground = inBackground;
    this.postExecute = postExecute;
  }

  public void onPreExecute() {
    handler = new Handler();
    if (preExecute != null) {
      handler.post(preExecute);
    }
  }


  public Void doInBackground(Void... params) {
    handler = new Handler();
    if (inBackground != null) {
      handler.post(inBackground);
    }
    return null;
  }

  public void onPostExecute(Void result) {
    handler = new Handler();
    if (postExecute != null) {
      handler.post(postExecute);
    }
  }
}
in a utility class. He used it whenever he needed operations to run in the background that don't need to return any values.

A COMPUTER GUY
Aug 23, 2007

I can't spare this man - he fights.

Glimm posted:

Looks like 4.4 KitKat has been announced, no SDK updates yet though:
http://www.android.com/kitkat/



Boy, isn't it great that there's gonna be another new Android version? 4.3's been out for like a whole month or something!

A COMPUTER GUY
Aug 23, 2007

I can't spare this man - he fights.

TheReverend posted:

I'm haveing an issue with an Exception
code:
 
E/AndroidRuntime(3565): android.view.WindowManager$BadTokenException: Unable to add window -- token null is not valid; is your activity running?
So the way my Activity works is that It takes information from a BT sensor and when it receives data it populates a popupWindow where you can edit the data and save it.

If you click on the graphical representation of the data, it populates the popupwindow with the saved data.

I can save new data and view old data just fine until I rotate the tablet. Then I can view data all I like, but new data causes this exception.

For the life of me I can't figure out what's going on.

Since nobody is answering you - my bet is that when you rotate your device, the activity is destroyed and relocated, and whatever populates the popupWindow is retaining the Context to the previous instance of the activity. Set your activity to handle rotation by adding android:configChanges="orientation" to its activity declaration in the Manifest and by implementing OnConfigurationChanged() in your activity. Or just have your activity pass along a new Context when it's recreated.

A COMPUTER GUY
Aug 23, 2007

I can't spare this man - he fights.
Yay, WebView will be less unusably bad now :toot: I anxiously await 2015 when 4.4 makes up 40% of the market

A COMPUTER GUY
Aug 23, 2007

I can't spare this man - he fights.
Why not pass the text as an extra to the new activity?

Adbot
ADBOT LOVES YOU

A COMPUTER GUY
Aug 23, 2007

I can't spare this man - he fights.

Tunga posted:

I guess you could check the Google accounts on the device against a hardcoded whitelist.

Alternately, add your device's serial number to a string array in resources and check against that.

code:
<?xml version="1.0" encoding="utf-8"?>
<resources>
    <string-array name="no_ad_devices">
        <item>butts</item>
    </string-array>
</resources>

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