Hi I have been having issues using the handler (I have used nearly every single example in any thread about looping stuff using handler)to loop a if statement that I need to rerun every 20 secs, I'm very new to java, and please ignore my stupid toast messages, could someone edit it so it will rerun the code every 20 seconds, Thanks in advance
DisplayManager dm = (DisplayManager) getSystemService(Context.DISPLAY_SERVICE);
for (final Display display : dm.getDisplays()) {
Toast.makeText(MainActivity.this, "for loop reached", Toast.LENGTH_LONG).show();
int state = display.getState();
String StateString = Integer.toString(state);
Toast.makeText(MainActivity.this, StateString, Toast.LENGTH_LONG).show();
if (display.getState() == 1) {
String command = "dumpsys deviceidle force-idle deep";
try {
Process process = Runtime.getRuntime().exec(command);
} catch (Exception e) {
Toast.makeText(MainActivity.this, "failed", Toast.LENGTH_LONG).show();
}
//Toast.makeText(MainActivity.this, "not failed yayay", Toast.LENGTH_LONG).show();
TextView tv9 = (TextView) findViewById(R.id.text_view_id);
tv9.setText("The screen was turned off");
Toast.makeText(MainActivity.this, "The screen is offfffffffff lolol", Toast.LENGTH_LONG).show();
} else {
Toast.makeText(MainActivity.this, "The screen is on lolol", Toast.LENGTH_LONG).show();
}
}