【发布时间】:2015-11-08 12:55:44
【问题描述】:
我有一个 Splash 活动,我希望通过 Intent 将用户重定向到不同的类,具体取决于它是否是第一次访问应用程序。
除了速度很慢之外,它还会崩溃
public class MainActivity extends Activity {
private long splashDelay = 1500;
int counter;
SharedPreferences app_preferences;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
app_preferences = PreferenceManager.getDefaultSharedPreferences(this);
counter = app_preferences.getInt("counter", 1);
System.out.println("count is..." +counter);
TimerTask task = new TimerTask() {
@Override
public void run() {
finish();
if(counter==1){
Intent in = new Intent(MainActivity.this, Attempt.class);
startActivity(in);
}
else{
Intent intent = new Intent().setClass(MainActivity.this, MainPage.class);
startActivity(intent);
}
SharedPreferences.Editor editor = app_preferences.edit();
editor.putInt("counter", +(counter+1));
editor.commit();
}
};
Timer timer = new Timer();
timer.schedule(task, splashDelay);
}
}
基本上,logcat 一直在继续,红色波浪的顶部表示“正在停止未恢复的活动:{yo.laststage/yo.laststage.MainPage}”
【问题讨论】:
-
错误提示
MainPage有问题。 -
感谢泰恩。我已经检查了清单和布局(只是一个文本视图)。还能是什么?
-
我的意思是,看起来
MainPage已经停止并且之前没有恢复。您的代码显示MainActivity。您未发布的代码可能存在问题。
标签: android android-intent sharedpreferences splash-screen