私は現在、アプリケーションが初めて開かれたときにセットアップインターフェイスとそれ以降のアプリケーションが開かれたときに、設定インターフェイスを表示するアプリケーションを開発中です。私がこれを達成したのは、アプリケーションが開くと、共有の設定がnullかどうかを確認することです。共有プリファレンスがnullの場合は、アプリケーションが初めて開かれたことを意味し、共有プリファレンスに値を設定します。次にアプリケーションが開かれたときに、共有設定がチェックされると、それはもはやヌルではなく、設定インターフェースに移動します。問題は、私が最初に実行すると、ステータスバーや何もない白い画面しか表示されないことです。以下は共有設定とインテントの使用 - セットアップと設定アプリケーション
private void saveSharedPref()
{
SharedPreferences preferences = getSharedPreferences(SHARED_PREFERENCES_FILE, 0);
SharedPreferences.Editor editor = preferences.edit();
//Save values from Edit Text Controls
editor.putString("firstTime", "1234");
editor.commit();
}
private void loadSharedPreferences()
{
SharedPreferences preferences = getSharedPreferences(SHARED_PREFERENCES_FILE, 0);
//Null check in case file does not exist
if(preferences != null) {
String checkFirst = preferences.getString("firstTime", "");
if (!checkFirst.equalsIgnoreCase("1234"))
{
Intent sendToSetup = new Intent (this, Setup.class);
startActivity(sendToSetup);
}
else
{
saveSharedPref();
}
}
}
私はloadSharedPreferences()を呼び出し、私onCreateMethodユーザーが初めてそれを開いたときにアプリがリダイレクトされる場所です
public class Setup extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.setup_pg1);
}
に自分のアプリケーションのコードスニペットです。
ご協力いただければ幸いです。前もって感謝します! P.P.申し訳ありませんが私の英語イマイチ良い
EDIT場合: はここandroidmanifest
<?xml version="1.0" encoding="utf-8"?>
<application
android:allowBackup="true"
android:icon="@drawable/icon1"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity
android:name=".SafeSwipe"
android:label="SafeSwipe-UI v.2"
android:theme="@style/AppTheme.NoActionBar">
</activity>
<activity
android:name=".MainActivity"
android:label=""
android:theme="@style/AppTheme.NoActionBar">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".Setup" />
</application>
setup_pg1
<TextView
android:text="Setup"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="102dp"
android:id="@+id/textView" />
<Button
android:text="Continue"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/textView"
android:layout_alignRight="@+id/textView"
android:layout_alignEnd="@+id/textView"
android:layout_marginTop="71dp"
android:id="@+id/button7" />
セットアップファイルです
public class Setup extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.setup_pg1);
}
}
詳細を表示する必要があります。可能であれば、あなたのアンドロイドマニフェストを投稿してください。R.layout.setup_pg1 – user3331142
@ user3331142質問を編集しました –
'getSharedPreferences'は途中で' null'を返すことはできません。常に有効なオブジェクトを返します。ただし、空にすることはできます。 –