FAQ Database Discussion Community


Android: can you access AsyncTask class members in DoInBackground?

java,android,multithreading,android-asynctask,android-handler
Is it safe to run a method of an AsyncTask class member inside the DoInBackground? or do you need to use a handler? private class MyAsyncTask extends AsyncTask<Void, Void, Void> { Object mObjA = null: private MyAsyncTask(Object objA) { mObjA = objA } protected void doInBackground(Void... params) { mObjA.aMethod() }...

Stopping a running handler

android,timer,android-handler
I have implemented a handler that allows the user to start an event that repeats every 5 seconds using the taskbar menu. What is the best method to use that would also allow the user to stop the event from the taskbar menu? public class MainActivity extends Activity{ @Override public...

Unable to update the UI using the message from the handler

android,multithreading,android-layout,android-handler
Hello everyone, I am new to android application development. I have written and code and trying to update the UI from the message obtained from handler. I have tried to debug the code but i couldn't find what the error is. please help me out. Thank you. package com.threadcommunicationexample; import...

IntentService and HandlerThread count

android,multithreading,android-handler,android-looper
I'm trying to understand how intentService do all work in single background thread, as docmentation says. So i dive into source code, and have a question public abstract class IntentService extends Service { private volatile Looper mServiceLooper; private volatile ServiceHandler mServiceHandler; private String mName; private boolean mRedelivery; private final class...

Android update UI on either gesture or after 5 seconds

android,multithreading,user-interface,timer,android-handler
I am a newbie to Android. I want to update a UI (GestureOverlayView) on either receiving a gesture or after 5 seconds. I am using- public void onGesturePerformed(GestureOverlayView overlay, Gesture gesture) { updateMyScreen(); } and this works great to update the screen but I want another thread which keeps tab...

Android Handler to refresh GUI

java,android,android-handler
I am trying to create a UI Handler to refresh the gridview after i execute the parseURL ASyncTask class and return an Arraylist back to the MainActivity to print out on the gridview. The code i have compiles and run without any errors but the gridview does not refresh after...

Android - Difference between Thread and AsyncTask?

java,android,android-asynctask,android-handler,java-threads
In my app i have buttons, when clicked will query the database and show result on screen. The query action will normally take 1 ~ 3 sec. These buttons will be clicked very often. I've implemented this action on both AsyncTask and Thread but see very little different. However in...

Getting GPS in service in android

android,gps,android-service,android-handler
My problem is not new, but none of answers in Stackoverflow was helpful for me. Situation: I have a service which works with an Alarm. it repeats every 1 minutes and run a service for me. in that service I need to send GPS data to a web server. the...

Handler & Runnable for Android Timer

java,android,handler,runnable,android-handler
I'm trying to display a String array in a TextView, one item at a time, every time an interval in milliseconds ends. I've been recommended this code: package com.tt.blanker; import android.app.Activity; import android.os.Bundle; import android.os.Handler; import android.util.Log; import android.widget.Button; import android.widget.TextView; import java.util.StringTokenizer; /** * Created by Gonzalo on 08/04/2015....

How can I programmatically cause a delay in Android?

java,android,timertask,android-handler,java-threads
I tried to use Thread.sleep() but it didn't work. When I use it, the app stops responding. I need to put some delays in my code like this: public void inicioJogo(){ for (int jogada = 1; jogada <= 50; jogada++) { for (int contador = 0; contador < jogada; contador++){...

Handler and Thread inside Service keeps running, while the Service seems to have stopped

java,android,multithreading,android-service,android-handler
I have a Service that uses Handler and Thread to run some code every 5 seconds. When I call stopSelf() the service seems to have stopped, because from the device Setting -> Apps -> Running it doesn't show there. But the code inside the thread keeps on running every 5...

Handling multiple Runnables() in Android

java,android,android-handler
I'm trying to animate 4 images in succession, switching the animation when I get a new GCM message that sends a Broadcast Intent. I'll show the code for the first 2, and what is going wrong. Basically between the two commands(case 0 vs case 1), I need to be able...

postDelayed() in a Service

android,android-service,android-handler
I'm trying to restart service from itself in a few time. My code looks like this (inside the onStartCommand(...)) Looper.prepare(); Handler handler = new Handler(); handler.postDelayed(new Runnable() { @Override public void run() { Intent intent = new Intent(BackgroundService.this, BackgroundService.class); startService(intent); } }, 3 * 60000); Service is running in the...

Issues with long running Handlers, Timers, and Tasks?

java,android,timer,android-handler
I've seen a number of questions using the Handler or Timer implementations in Android apps to delay an update to the UI thread. Most of these seem to be short - a few seconds at most. Are there issues with using a 24 hour delay for a task? How does...

Scheduling recursive handlers from an IntentService for retrying http calls

java,android,multithreading,android-handler,android-intentservice
I am trying to implement exponential backoff for retrying failed http calls by scheduling a thread with handler.postDelayed(...) every time my request fail. The problem is that I am doing this from an IntentService which dies after scheduling the first thread so the handler is not able to call itself....

Handling offline events

android,caching,event-handling,offline-caching,android-handler
I am doing offline caching.I want to allow user to make events even when he/she is offline.For that I am using a handler that checks every second whether net connection is there or not and whenever net connection is there it executes the task associated with the event.For example if...

View recycling in listview causes postDelayed() issue

android,runnable,android-handler,postdelayed
I have a list of user tasks/to-dos which have deadlines associated with it. Every minute on the minute I update the TextView that shows the time remaining for these task. The problem I have is that some times when the textview gets updated the wrong time remaining gets displayed, especially...

Android Runnable Handler not stop at specified intervals(seconds)

java,android,runnable,android-handler
I am using Runnable Handler to update my UI at specified intervals . However on button click event my this timer stops but at specified intervals it continues to go own . Here is my code . public class MainActivity extends ActionBarActivity { public TextView myCounter; private int mInterval=50; private...

How can I trigger my notification from a method?

android,android-notifications,android-handler,android-looper
I am trying to trigger my notification bottom. I followed this example code http://www.compiletimeerror.com/2013/10/status-bar-notification-example-in.html#.VWtoS1xViko I can trigger the notification when I call the method from my HomeActivity which is my main activity for the app. When try to call from one of the methods within the app, nothing happens. (eg)...