我不知道是什麼導致了這種情況 - 我在一些場合使用了片段並覆蓋了後退按鈕,但總體而言沒有任何明顯的跡象表明這是爲什麼發生。應用程序第一次在應用程序啓動後顯示白屏的應用程序
我已經檢查了logcat,沒有任何註釋顯示爲什麼發生這種情況 - 有沒有人有任何想法可能是什麼問題或檢查什麼?
沒有對onDestroy進行手動調用。
一旦我意識到存在問題,然後我試着找出在生命週期中這將會發生多久,並且應用程序在安裝時加載正常,然後如果我登錄到應用程序然後殺死應用程序,我無法加載它再次,我只是得到一個白色的屏幕如下所示。
Android清單
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.year3.practise">
<uses-permission android:name="android.permission.INTERNET" />
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
MainActivity
public class MainActivity extends AppCompatActivity {
private SharedPreferences pref;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
pref = getPreferences(0);
//initialise method
initFragment();
}
private void initFragment(){
Fragment fragment;
if(pref.getBoolean(Constants.IS_LOGGED_IN,false)){
fragment = new ProfileFragment();
}
else {
fragment = new QuestionPinFragment();
// update the main content by replacing fragments
FragmentManager fragmentManager = getSupportFragmentManager();
fragmentManager.beginTransaction()
.replace(R.id.fragment_frame, fragment)
.commit();
}
}
}
後AndroidManifest.xml後,你的MainActivity代碼請 –
@JuanCruzSoler,我加入了兩個 - 感謝試圖幫助。 –