2017-03-16 81 views
-2
package com.dswipu.dswipu; 

import android.content.Intent; 
import android.os.Handler; 
import android.support.v7.app.AppCompatActivity; 
import android.os.Bundle; 
import android.view.Menu; 
import android.view.MenuItem; 
import android.view.Window; 
import android.widget.Toast; 

public class splash extends AppCompatActivity { 

    private static int SPLASH_TIME_OUT = 5000; 
    private UserSessionManager session; 
    @Override 
    protected void onCreate(Bundle savedInstanceState) 
    { 


     super.onCreate(savedInstanceState); 
     getWindow().requestFeature(Window.FEATURE_ACTION_BAR); 
     getActionBar().hide(); 
     setContentView(R.layout.activity_splash); 

      Utility ut = new Utility(this); 
     if(!ut.checkInternet()) 
     { 

      Toast.makeText(getApplicationContext(), "No internet connection", 
        Toast.LENGTH_LONG).show(); 

     } 
     new Handler().postDelayed(new Runnable() { 

      /* 
      * Showing splash screen with a timer. This will be useful when you 
      * want to show case your app logo/company 
      */ 

      @Override 
      public void run() { 
       // This method will be executed once the timer is over 
       // Start your app main activity 
       session = new UserSessionManager(getApplicationContext()); 
       if (session.isUserLoggedIn()) { 

        Intent i = new Intent(getApplicationContext(), Home.class); 
        startActivity(i); 

       } else { 
        Intent i = new Intent(splash.this, Auth.class); 
        startActivity(i); 
       } 
       // close this activity 
       finish(); 

      } 
     }, SPLASH_TIME_OUT); 
    } 

} 

十一月3日至16日:43:47.932 4037-4037/com.dswipu.dswipu E/AndroidRuntime:致命異常:主 工藝:com.dswipu.dswipu,PID:4037 java.lang中。 RuntimeException:無法啓動活動ComponentInfo {com.dswipu.dswipu/com.dswipu.dswipu.splash}:android.util.AndroidRuntimeException:requestFeature()必須在添加內容之前調用 at android.app.ActivityThread.performLaunchActivity( ActivityThread.java:2416) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476) at android.app.ActivityThread.-wrap11(ActivityThread.java) at android.app.ActivityThread $ H.handleMessage(ActivityThread.java:1344) at android.os.Handler.dispatchMessage(Handler.java:102) at android.os.Looper.loop(Looper.java:148) at android.app.ActivityThread.main(ActivityThread.java:5417) at java.lang.reflect.Method.invoke(Native Method) at com。 android.internal.os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit.java:726) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616) 引起:android.util。 AndroidRuntimeException:必須在添加內容之前調用requestFeature() at com.android.internal.policy.PhoneWindow.requestFeature(PhoneWindow.java:317) at com.dswipu.dswipu.splash.onCreate(splash.java:22 ) 在android.app.Activity.performCreate(Activity.java:6237) 在android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1107) 在android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2369) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476) at android.app.ActivityThread.-wrap11(ActivityThread.java) at android.app.ActivityThread $ H.handleMessage(ActivityThread.java:1344) at android.os.Handler.dispatchMessage(Handler.java:102) at android.os.Looper.loop(Looper.java:148) at android.app.ActivityThread.main(ActivityThread.java:5417) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit.java :726) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616) 03-16 11:43:47.934 1685-2328/system_process W/ActivityManager:強制結束活動com.dswipu.dswipu/.splash 03-16 11:43:48.237 1685-2328/system_process I/Wind owManager:截圖max retries 4令牌{e07b2da ActivityRecord {2395485 u0 com.dswipu.dswipu/.splash t17 f}} appWin = Window {8f28f3d u0 Starting com.dswipu.dswipu} drawState = 4 03-16 11:43: 48.268 2501-4094/com.google.android.gms D/DropBoxEntryAddedChimeraService:用戶未選擇使用&診斷。 03-16 11:43:48.296 1685-2572/system_process I/OpenGLRenderer:初始化的EGL 1.4版如何糾正這個錯誤「java.lang.RuntimeException:無法啓動活動ComponentInfo」?

+0

任何解釋老兄?我們如何設想知道這個問題? –

+0

在setContentview(R.layout.lay)之前調用requestFeature()方法 – Vadivel

+0

我應該提供哪些代碼?以幫助我的問題得到解決更好..... –

回答

1

for AppCompatActivity requst功能應在超級調用onCreate之前調用。

public class splash extends AppCompatActivity { 

    private static int SPLASH_TIME_OUT = 5000; 
    private UserSessionManager session; 
    @Override 
    protected void onCreate(Bundle savedInstanceState) 
    { 

     getWindow().requestFeature(Window.FEATURE_ACTION_BAR); 
     super.onCreate(savedInstanceState); 
     getActionBar().hide(); 
     setContentView(R.layout.activity_splash); 
. 
. 
. 

    } 
} 

爲了使活動的全屏幕,你也可以將下面的代碼添加到您的「風格」的xml文件,如果犯規存在,在價值創造它

<style name="AppFullScreenTheme" parent="Theme.AppCompat.Light.NoActionBar"> 
    <item name="android:windowNoTitle">true</item> 
    <item name="android:windowActionBar">false</item> 
    <item name="android:windowFullscreen">true</item> 
    <item name="android:windowContentOverlay">@null</item> 
</style> 
清單文件

然後將此主題到您的活動:

<activity 
     android:name=".ui.activity.SplashActivity" 
     android:screenOrientation="portrait" 
     android:theme="@style/AppFullScreenTheme"> 
     <intent-filter> 
      <action android:name="android.intent.action.MAIN" /> 

      <category android:name="android.intent.category.LAUNCHER" /> 
     </intent-filter> 
</activity> 
+0

是否需要刪除hide()函數?因爲它的工作我真的需要幫助。 –

+0

你需要完成什麼?只是一個全屏的活動? –

+0

@HarshGantara是的。 –

相關問題