0
我有一个Splash活动,其中通过意图,我希望用户根据是否第一次访问该应用程序而被重定向到不同的类。危险的组合Splash +共享首选项
除了是很慢,崩溃
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 /哟.laststage.MainPage}”
的错误表示'MainPage'问题。 – tynn
谢谢Tynn。我已经检查了清单和布局(只是一个textview)。它还能是什么? – MDR
我的意思是,它看起来像'MainPage'已经停止,并没有恢复之前。你的代码显示了'MainActivity'。您没有发布的代码可能存在问题。 – tynn