Note that there are some explanatory texts on larger screens.

plurals
  1. POImplementing Handlers the basic way
    primarykey
    data
    text
    <p>Ok, so i've read many tutorials and threads on handlers but they seem to be more advance with my own knowledge of handlers, this is the first time i've used handlers so bare with me. I have this sample application on handlers which fires a Log at a certain time, but its seems to be not working when i clicked my start button. Below is my code. </p> <pre><code>public class Main extends Activity { private long selectedTimeInMills; private Handler handler; private static final Calendar CALENDAR = Calendar.getInstance(); @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); TimePicker timepicker = (TimePicker) findViewById(R.id.timePicker1); final TextView timeText = (TextView) findViewById(R.id.time); Button start = (Button) findViewById(R.id.button1); handler = new Handler(); String textTime = formatDate(CALENDAR.getTimeInMillis(), "hh:mm a"); timeText.setText(textTime); timepicker.setOnTimeChangedListener(new OnTimeChangedListener() { public void onTimeChanged(TimePicker view, int hourOfDay, int minute) { CALENDAR.set(Calendar.HOUR_OF_DAY, hourOfDay); CALENDAR.set(Calendar.MINUTE, minute); selectedTimeInMills = CALENDAR.getTimeInMillis(); String textTime = formatDate(CALENDAR.getTimeInMillis(), "hh:mm a"); timeText.setText(textTime); } }); start.setOnClickListener(new OnClickListener() { public void onClick(View v) { Runnable runnable = new Runnable() { public void run() { Log.d("HandlerCheck", "Handler Fired! @ ("+selectedTimeInMills+") "+formatDate(selectedTimeInMills, "hh:mm a")); } }; boolean flag = handler.postAtTime(runnable, selectedTimeInMills); Toast.makeText(Main.this, "Handler is Fired?:: "+flag, Toast.LENGTH_LONG).show(); } }); } } </code></pre> <p>NOTE: when i clicked on my button and it implement the <code>handler.postAtTime()</code> it returns <code>true</code> but still it won't display the Log on DDMS even though i've set my timepicker 1 min from the current time still won't fire the Log message on DDMS</p>
    singulars
    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.
 

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