Hello I am new to android and java I need help !! In this code i am traying to keep the countdown working after destroying or stopping the application (android) i want the phone to lock even if i stop the application you can see the code below i know i need onStop(); method but i don't know what to type inside it thanks by advance
public class SetTimeActivity extends AppCompatActivity {
Button set_btn ;
int min ;
EditText setTimerMenu_et;
TextView tv_display ;
DevicePolicyManager devicePolicyManager;
ComponentName componentName;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_set_time);
set_btn = (Button)findViewById(R.id.set_btn);
setTimerMenu_et = (EditText)findViewById(R.id.setTimerMenu_et);
tv_display = (TextView)findViewById(R.id.tv_display);
devicePolicyManager = (DevicePolicyManager) getSystemService(Context.DEVICE_POLICY_SERVICE);
componentName = new ComponentName(SetTimeActivity.this , Controller.class);
//-------------------------Clicking SET button---------------------------------
set_btn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String text = setTimerMenu_et.getText().toString();
if(!text.equalsIgnoreCase(""));
int toMin = Integer.valueOf(text);
min = toMin*60000;
tv_display.setText("The Phone will lock after: " + text + " minute");
CountDownTimer countDownTimer = new CountDownTimer(min,10000) {
@Override
public void onTick(long ms) {
}
@Override
public void onFinish() {//when the timer end the phone will lock
devicePolicyManager.lockNow();
}
}.start();
}
});
}
}`