Having Trouble with my Splash Screen

前端 未结 2 1328
[愿得一人]
[愿得一人] 2021-01-29 12:47

So I just started to set up a splash screen that would show for 5 seconds and then go to my main menu. I think I labeled something wrong in the process and now my app is force c

相关标签:
2条回答
  • 2021-01-29 13:14

    In your thread, try changing:

     Intent DragonFruitActivityIntent = new Intent("main");
    

    to:

     Intent DragonFruitActivityIntent = new Intent(DragonFruitActivity.this, NameOfActivityToStart.class);
    

    Alternatively, if you want to change the layout rather than starting a new activity, remove:

    Intent DragonFruitActivityIntent = new Intent("main");
    startActivity(DragonFruitActivityIntent);
    

    and instead write:

    DragonFruitActivity.this.setContentView(R.layout.main);
    

    Incidentally, it would be better if rather than sleeping for 5 seconds, the thread did something useful like load some data for your app - otherwise it's just slowing down access to your app for no reason.

    Edit: Try moving all your code from onCreate() to onStart(), so it's like this:

    @Override
    public void onCreate(Bundle savedInstanceState) {
       super.onCreate(savedInstanceState);
       requestWindowFeature(Window.FEATURE_NO_TITLE);
       getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
          WindowManager.LayoutParams.FLAG_FULLSCREEN);        
       setContentView(R.layout.splash);
    }
    
    @Override
    public void onStart() {
       super.onStart()
       Thread logoTimer = new Thread() {
       ... // the rest of your code here
    }
    

    You may be experiencing problems accessing the UI before it's fully formed.

    0 讨论(0)
  • 2021-01-29 13:17

    As your log cat suggests..

    at com.Dragon_Fruit.DragonFruitActivity.onCreate(DragonFruitActivity.java:44)
    

    There's some problem in your DragonFruitActivity file. On line 44 inside OnCreate callback..

    I guess removing that can solve the issue of NullpointerException.

    0 讨论(0)
提交回复
热议问题