Note that there are some explanatory texts on larger screens.

plurals
  1. POAndroid Java - Message at a random range of time, every second check
    primarykey
    data
    text
    <p>For a side project of mine, I'm devoloping an android app with java. I don't know java a lot but i'm trying ^^.</p> <p>The project is to have an Alarm at a random time in a certain range. The problem is that my chronometer and button freeze, but everything still works! Does anyone has maybe another solution for the thread.sleep ??</p> <pre><code> public class MainActivity extends Activity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); } public void StartChrono(View view) { final Chronometer chrono = (Chronometer)findViewById(R.id.chronometer1); chrono.setBase(SystemClock.elapsedRealtime()); chrono.start(); //Tick(); } public int RandomTime(int min, int max) { int random = max - min; Random rand= new Random(); random = rand.nextInt(random)+min; return random; } public boolean CheckUp(int randomtime,int chronotime) { boolean check = false; if(randomtime== chronotime) { check = true; } return check; } public void Tick() { boolean check = false; int randomtime = RandomTime(20,150); int time=1; do { check = CheckUp(randomtime,time); time = time +1; try { Thread.sleep(1000); } catch (InterruptedException e) { AlertDialog alertDialog; alertDialog = new AlertDialog.Builder(this).create(); alertDialog.setTitle("Error - 000"); alertDialog.setMessage("Could not check!"); alertDialog.show(); } }while(check == false); if(check == true) { AlertDialog alertDialog; alertDialog = new AlertDialog.Builder(this).create(); alertDialog.setTitle("Yuy"); alertDialog.setMessage("Switch!"); alertDialog.show(); } } } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload