0
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
SharedPreferences getPrefs = PreferenceManager.getDefaultSharedPreferences(getBaseContext());
boolean isStart = getPrefs.getBoolean("firstStart",true);
if(!isStart){
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
Intent homeIntent = new Intent(MainActivity.this,HomeAcitivity.class);
startActivity(homeIntent);
finish();
}
},3000);
}
else{
Intent intent = new Intent(MainActivity.this,IntroActivity.class);
startActivity(intent);
}
SharedPreferences.Editor e =getPrefs.edit();
e.putBoolean("firstStart",false);
e.apply();
}
}如何在android中添加啓動屏幕以及Intro Screen?
我在Android應用程序開發初學者。我想在用戶進入屏幕時第一次顯示Intro屏幕(使用AppIntro庫),並且從第二次開始,應用程序應顯示啓動屏幕?
我遇到以下錯誤,當我遵循上面的代碼?
FATAL EXCEPTION: Thread-23386
Process: gajapathy.com.volunteers, PID: 17022
java.lang.RuntimeException: Can't create handler inside thread that has not called Looper.prepare()
at android.os.Handler.<init>(Handler.java:200)` at android.os.Handler.<init>(Handler.java:114)
at gajapathy.com.volunteers.MainActivity$1.run(MainActivity.java:27)
at java.lang.Thread.run(Thread.java:818)`
它不工作。其實我不需要睡覺,只要我啓動應用程序所以我試圖在if條件內添加sleep()。但我沒有得到 –