0

I am trying to make a toast in specific time, but when I start the emulator and wait for the minute to change it doesn't do anything. Reloading the application shows the toast message (just in that minute).

public class Awkat_sala_lodActivity extends Activity {

MediaPlayer myAudio;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
    Calendar ci = Calendar.getInstance();

    String CiDateTime =   
         (ci.get(Calendar.MONTH) + 1) + "/" +
         ci.get(Calendar.DAY_OF_MONTH) + "   " +
         ci.get(Calendar.HOUR_OF_DAY) + ":" +
         ci.get(Calendar.MINUTE);
 myAudio = MediaPlayer.create(this, R.raw.ce);


/////
        if(ci.get(Calendar.MONTH) + 1 == 4) {
            if(ci.get(Calendar.DAY_OF_MONTH) == 10){
                if(ci.get(Calendar.HOUR_OF_DAY) == 20 ){
                    if(ci.get(Calendar.MINUTE) ==05){
                         Toast.makeText(Awkat_sala_lodActivity.this, "test", Toast.LENGTH_LONG).show();
                        myAudio.start();

                            }
            } 

What do I have to change in order to get the program to work on time without having to refresh it?

4

1 回答 1

1

在你的 Toast 中尝试 getApplicationContext() ......

Toast.makeText(getApplicationContext(), "test", Toast.LENGTH_LONG).show();
myAudio.start();
于 2013-01-22T10:12:46.737 回答