Toast消息未按时出现

时间:2012-04-10 20:37:31

标签: toast

我正在尝试在特定时间举杯,但是当我启动模拟器并等待分钟更改时它没有做任何事情。重新加载应用程序会显示Toast消息(仅在那一分钟内)。

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();

                            }
            } 

为了让程序按时运行而不必刷新,我需要更改什么?

1 个答案:

答案 0 :(得分:1)

尝试使用吐司中的getApplicationContext()...

Toast.makeText(getApplicationContext(), "test", Toast.LENGTH_LONG).show();
myAudio.start();