Relm
Relm

Reputation: 8282

Android Java : Are methods called from an AsyncTask also running in the background thread?

On main Activity, I do the following to have these methods run in the background thread.

private void doInBackground() {
      final Activity a = this;
      AsyncTask.execute(new Runnable() {
         @Override
         public void run() {
            bindDb();
            new MessageSynchronizer(a);
            NotifHelper.cancelNotifications(a);
            MessageHelper.updateMyLastSeen();
            versioning();
         }
      });
}

Then I want to know if the following method, called from above is running in the UiThread or the thread which called it above.

private void bindDb() {
      DatabaseHelper databaseHelper = new DatabaseHelper(this);
      databaseHelper.getWritableDatabase();
      databaseHelper.getDatabaseName();
      databaseHelper.close();
}

Upvotes: 0

Views: 80

Answers (1)

M A
M A

Reputation: 72864

It's on the background thread, i.e. the thread used by ASyncTask. That's due to pure Java execution semantics: a method being invoked by a method running on a thread gets executed on the same thread.

You can also verify this by checking the current thread as shown in this post.

Upvotes: 2

Related Questions