i have been trying to detect user inactiveness in my app, and did find a code on stackoverflow which did marvelously but the issue is that, when am in another app, lets say Whatsapp once the timer is up in my app, my app just pop over the screen, I dont want it so, i dont want my app popping up each time the timer has count-down due to inactiveness.
Original code by Pradeep Gupta
Please, how will i accomplish that??
Here is my Code
public abstract class BaseActivity extends AppCompatActivity {
Handler handler;
Runnable r;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
handler = new Handler();
r = new Runnable() {
@Override
public void run() {
// TODO Auto-generated method stub
Toast.makeText(BaseActivity.this, "user is inactive from last 5 minutes",Toast.LENGTH_SHORT).show();
Intent intent = new Intent(BaseActivity.this,
VendorHub.class);
startActivity(intent);
finish();
}
};
startHandler();
}
@Override
public void onUserInteraction() {
// TODO Auto-generated method stub
super.onUserInteraction();
stopHandler();//stop first and then start
startHandler();
}
public void stopHandler() {
handler.removeCallbacks(r);
}
public void startHandler() {
handler.postDelayed(r, 1*60*1000); //for 5 minutes
}
}