不跳到主要活动

时间:2013-08-02 06:50:59

标签: android android-intent android-activity android-preferences splash-screen

大家好我第一次使用启动活动,或者他从我的应用程序注销了。但这经常出现在三星Galaxy S2上。这是我的活动onCreate()方法代码

private static EditText serverIP = null;
String mMDCServerIP = "";
String skipSplashScreenStatus = null;
String mSplashScreenRunningStatus = null;
String mDeniedStatusFromServer = null;
public void onCreate(Bundle savedInstance)
{
    super.onCreate(savedInstance);
    /** Get the MDC IP **/
    Log.d("splash","1111111111111111");
    skipSplashScreenStatus = Config.getSetting(getApplicationContext(),"SPLASHSTATUS");
    mSplashScreenRunningStatus = Config.getSetting(getApplicationContext(),"SPLASHACTIVITYRUNNINGSTATUS");
    mDeniedStatusFromServer =  Config.getSetting(getApplicationContext(),"DENYSTATUS");
    if(skipSplashScreenStatus == null || skipSplashScreenStatus.length() == 0)
    {
        Config.setSetting(getApplicationContext(),"DENYSTATUS","false");
    }
    /** If SPLASHSTATUS does not exist then store the SPLASHSTATUS as false**/
    if(skipSplashScreenStatus == null || skipSplashScreenStatus.length() == 0)
    {
        Config.setSetting(getApplicationContext(),"SPLASHSTATUS","false");
    }
    if(mSplashScreenRunningStatus == null || mSplashScreenRunningStatus.length() == 0)
    {
        Config.setSetting(getApplicationContext(),"SPLASHACTIVITYRUNNINGSTATUS","yes");
    }
    Log.d("splash","222222222222222222");
    Log.d("splash","skipSplashScreenStatus : "+skipSplashScreenStatus);
    skipSplashScreenStatus = Config.getSetting(getApplicationContext(),"SPLASHSTATUS");
    if(skipSplashScreenStatus!= null && skipSplashScreenStatus.equalsIgnoreCase("yes"))
    {
        Log.d("splash","inside if condition");
        skipSplashScreen();         
    }
else{
    Log.d("splash","inside else condition");
    setContentView(R.layout.splash_screen);
    Log.d("SPLASH","33333333333333");
    serverIP =  (EditText) findViewById(R.id.splash_server_ip);
    /** Get the MDC IP **/
    mMDCServerIP = Config.getSetting(getApplicationContext(),"IPADDR");
    /** If MDC IP does not exist then store the IP as 0.0.0.0**/
    if(mMDCServerIP == null || mMDCServerIP.length() == 0)
    {
        Config.setSetting(getApplicationContext(),"IPADDR","0.0.0.0");
    }
serverIP.setOnEditorActionListener(new EditText.OnEditorActionListener() 
    {
        @Override
        public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
        if (actionId == EditorInfo.IME_ACTION_SEARCH ||
                actionId == EditorInfo.IME_ACTION_DONE ||
                event.getAction() == KeyEvent.ACTION_DOWN &&
                event.getKeyCode() == KeyEvent.KEYCODE_ENTER) {
Config.setSetting(getApplicationContext(),"SPLASHSTATUS","yes");   
Config.setSetting(getApplicationContext(),"SPLASHACTIVITYRUNNINGSTATUS","no");
skipSplashScreen();
}}}}

以下是skipSplashScreen();

的代码
private void skipSplashScreen()
{
    try{
        Log.d("splash","inside skipSplashScreen 111");
        CommandHandler.mStopSendingKeepAlive = false;
        Log.d("splash","inside skipSplashScreen 222");
        startActivity(new Intent(getApplicationContext() ,SecondTest.class));
    }
    catch(Exception e)
    {
        Log.d("splash","Exception in skipSplashScreen 333");
        Log.d("splash",e.getMessage());
    }
}

一旦我深入研究代码,似乎控制是skipSplashScreen()方法但不启动第二个活动。我可以知道可能是什么原因。

1 个答案:

答案 0 :(得分:1)

尝试此操作,在开始活动时,请使用Activity.this代替getApplicationContext()

private void skipSplashScreen()
{
    try{
        Log.d("splash","inside skipSplashScreen 111");
        CommandHandler.mStopSendingKeepAlive = false;
        Log.d("splash","inside skipSplashScreen 222");
        startActivity(new Intent(SplashScreen.this ,SecondTest.class));
    }
    catch(Exception e)
    {
        Log.d("splash","Exception in skipSplashScreen 333");
        Log.d("splash",e.getMessage());
    }
}