我的应用程序中出现了一个非常神秘的错误。在 Android Studio 上,我在第一个 Activity(Launcher Activity)上检查SharedPreferences中的值,如果我得到一个值,应用程序应该进入后台,否则将显示 Activity。
问题是:当应用程序首次启动时,它会进入后台。但在第二次,它正在显示活动。同样,(对于第三次启动),应用程序将进入后台。没有调试点在工作。也没有显示任何日志。请帮助我摆脱这个神秘的问题。
谢谢。
Edited:
public class SecureAppsMainAct extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
loadSavedPreferences();
}
private void loadSavedPreferences() {
SharedPreferences sp_lockcode = PreferenceManager
.getDefaultSharedPreferences(this);
String set_code = sp_lockcode.getString("LOCKCODE_SET", "");
Log.e("set code", set_code + "");
if (set_code.length() > 1) {
//finish();
Intent i = new Intent();
i.setAction(Intent.ACTION_MAIN);
i.addCategory(Intent.CATEGORY_HOME);
this.startActivity(i);
} else {
Log.e("Load Prefs not working", "Load Prefs not working");
Intent i = new Intent(SecureAppsMainAct.this, Main.class);
startActivity(i);
}
}
}
清单文件:
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name" >
<activity android:name="com.example.checkcurrentrunningapplication.SecureAppsMainAct"
android:label="@string/app_name"
android:theme="@android:style/Theme.Dialog">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name="com.example.checkcurrentrunningapplication.Main">
</activity>
<activity android:name="com.example.checkcurrentrunningapplication.LockDialog"></activity>
<activity android:name="com.example.checkcurrentrunningapplication.UnlockingAct"
android:theme="@android:style/Theme.Dialog"></activity>
<receiver android:name="com.example.checkcurrentrunningapplication.StartupReceiver">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
<action android:name="StartupReceiver_Manual_Start" />
</intent-filter>
</receiver>
<receiver android:name = "com.example.checkcurrentrunningapplication.CheckRunningApplicationReceiver"/>
</application>