I have to upload data to a server. I am using a service that is running on the same process as my application. Should I use a Separate thread for upload process or Should I
Yes you can, the below code will run every 5 seconds. Use your regular connection code for sending part.
public class AsyncTaskInServiceService extends Service {
public AsyncTaskInServiceService() {
super("AsyncTaskInServiceService ");
}
@Override
public void onCreate() {
// TODO Auto-generated method stub
super.onCreate();
}
@Override
protected void onHandleIntent(Intent intent) {
final Timer t = new Timer();
t.scheduleAtFixedRate(new TimerTask() {
@Override
public void run() {
//Connect to database here
try {
} catch (JSONException e) {
e.printStackTrace();
}
}
}, 0, 5000);
}
}