一项活动。当按下主页按钮时,它将运行 OnPause 方法,并在 5 秒后显示自己的活动。这是我想要但做不到的。我的错误是什么?
package cem.examples.listviewActivity;
import java.util.Timer;
import java.util.TimerTask;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.widget.Toast;
public class main extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
}
@Override
protected void onPause() {
super.onPause();
Timer timer = new Timer();
timer.schedule(new TimerTask() {
@Override
public void run() {
Toast.makeText(main.this, "Timer RUN", Toast.LENGTH_SHORT).show();
new Runnable() {
@Override
public void run() {
Toast.makeText(main.this, "5000 msec ok", Toast.LENGTH_SHORT).show();
Intent intt = new Intent(main.this, main.class);
intt.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(intt);
}
};
}
}, 5000);
}
}