i want to update a table in my app database which is only possible when i relaunch the app. So, is it possible to quit or relaunch the android app programmatically, after a certain interval of time when user is not interacting with app or user has put the app in back ground.
Asked
Active
Viewed 1,341 times
3
-
Why do you need to relaunch app to update DB? Any specific reason? – Aradhna May 23 '16 at 05:51
-
When you say you want to update a DB, do you mean update a column, or you mean add a column/change a column name/etc...? Updating a field WITHIN a column of a table doesn't require a restart. However, a change to the table name, etc... does require a restart,etc... and you will also need to increment the DB version I believe. – ngoctranfire May 23 '16 at 06:01
-
because on relaunch of the app, user has to go through login process where i am checking the user status on my server wether it is activated or deactivated then i saved/update it in my database. – sunil kushwah May 23 '16 at 06:11
1 Answers
0
just extends this base activty instead of AppCompatActivity
public class BaseAppCompactActivity extends AppCompatActivity {
//activity restart this timeout
public static final long DISCONNECT_TIMEOUT = 14400000; // 5 min = 5 * 60 * 1000 ms
private Handler disconnectHandler = new CustomHandler();
private Runnable disconnectCallback = new Runnable() {
@Override
public void run() {
// Perform any required operation on disconnect
finishAffinity();
}
};
public void resetDisconnectTimer(){
disconnectHandler.removeCallbacks(disconnectCallback);
disconnectHandler.postDelayed(disconnectCallback, DISCONNECT_TIMEOUT);
}
public void stopDisconnectTimer(){
disconnectHandler.removeCallbacks(disconnectCallback);
}
@Override
public void onUserInteraction(){
resetDisconnectTimer();
}
@Override
public void onResume() {
System.out.println("Base Activity Resume called");
super.onResume();
resetDisconnectTimer();
}
@Override
public void onStop() {
System.out.println("Base Activity Stop called");
super.onStop();
stopDisconnectTimer();
}
static class CustomHandler extends Handler {
public void handleMessage(Message msg) {
}
}
@Override
public void onBackPressed() {
super.onBackPressed();
}
}

sunil kushwah
- 495
- 1
- 6
- 20