android - A blank screen appears when starting another activity from inside onCreate() -


i working on android application. have started coding it. want have initial activity check if user logged in. if yes, redirect user's home page, otherwise it'll redirect user login/signup page.

for now, have created simple main activity, should show progress bar. i've added 5sec delay , activity should direct user login page (i've not kept button on page). activity creates intent , start other activity using after 5 sec delay. i'll store user's login state in shared preference later.

the problem when run app on device, shows blank screen (not progress bar had put) 5 sec , redirects login page. i'm doing wrong?

here's activity_main.xml file

<?xml version="1.0" encoding="utf-8"?> <linearlayout xmlns:android="http://schemas.android.com/apk/res/android"     android:id="@id/main_layout"     android:layout_width="match_parent"     android:layout_height="match_parent"     android:orientation="vertical">      <progressbar         android:id="@id/firstprogress"         style="@android:style/widget.progressbar"         android:layout_height="wrap_content"         android:layout_width="wrap_content"         android:layout_gravity="center"         android:layout_margintop="40dp">     </progressbar> </linearlayout> 

and here's mainactivity.java file

package com.example.neeraj.myapplication;  import android.app.activity; import android.app.notification; import android.content.intent; import android.os.bundle; import android.os.systemclock; import android.view.menu; import android.view.menuitem; import android.view.view; import android.widget.edittext; import android.widget.linearlayout; import android.widget.progressbar; import android.widget.radiogroup; import android.widget.toast;  import com.facebook.accesstoken; import com.facebook.accesstokentracker; import com.facebook.callbackmanager; import com.facebook.facebookactivity; import com.facebook.facebookcallback; import com.facebook.facebookexception; import com.facebook.facebooksdk; import com.facebook.login.loginresult; import com.facebook.login.widget.loginbutton;  public class mainactivity extends activity {      @override     protected void oncreate(bundle savedinstancestate) {         super.oncreate(savedinstancestate);         setcontentview(r.layout.activity_main);         systemclock.sleep(5000);         intent = new intent(mainactivity.this, loginactivity.class);         startactivity(i);     }      @override     public boolean oncreateoptionsmenu(menu menu) {         // inflate menu; adds items action bar if present.         getmenuinflater().inflate(r.menu.menu_main, menu);         return true;     }      @override     public boolean onoptionsitemselected(menuitem item) {         // handle action bar item clicks here. action bar         // automatically handle clicks on home/up button, long         // specify parent activity in androidmanifest.xml.         int id = item.getitemid();          //noinspection simplifiableifstatement         if (id == r.id.action_settings) {             return true;         }          return super.onoptionsitemselected(item);     }      @override     public void ondestroy() {         super.ondestroy();     } } 

by using thread.sleep() or systemclock.sleep() blocking main thread of app, responsible displaying ui. use handler.postdelayed() instead.


Comments

Popular posts from this blog

Android : Making Listview full screen -

javascript - Parse JSON from the body of the POST -

javascript - How to Hide Date Menu from Datepicker in yii2 -