2015-11-13 101 views
2

我有三個頁面Splash_Activity,Login_Activity,Activity_One安卓:如何啓動兩項活動

活動流Splash_Activity - > Login_Activity - > Activity_One。在這種情況下,我檢查.db文件中存在或不是我的始終啓動應用程序的Splash_Activity。

我把條件是否存在名爲.db然後去Activity_One 如果沒有的話去Login_Activity。

但是,當我在按鈕刪除.db文件的問題點擊.db文件被正確刪除,顯示登錄頁面。

當我不存在登錄時應用程序,我再次啓動應用程序前兩點三倍運行,並檢查.db文件不可用,則去到登錄頁面,但之後它去Activity_One。爲什麼出現這種情況

這個閃屏

public class Splash_Screen extends RootActivity 
{ 
    MyDbHelper dbhelper ; 

    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     this.requestWindowFeature(Window.FEATURE_NO_TITLE); 
     setContentView(R.layout.splash_page); 

     Thread loading = new Thread() { 
      public void run() 
      { 
       try 
       { 
        File database=getApplicationContext().getDatabasePath("ClassNKK.db"); 

        if (!database.exists()) { 
         // Database does not exist so copy it from assets here 
         Log.i("Database", "Not Found"); 
         try 
         { 
          sleep(2000); 
          Intent main = new Intent(Splash_Screen.this, Login_Screen.class); 
          startActivity(main); 
          Log.e("DB "," is null !!!"); 
         } 

         catch (Exception e) { 
          e.printStackTrace(); 
         } 

        } 
        else { 
         Log.i("Database", "Found"); 
         try { 
          sleep(2000); 
          Intent main = new Intent(Splash_Screen.this, AllPosts_Page.class); 
          startActivity(main); 
          Log.e("DB ", " is null !!!"); 
         } catch (Exception e) { 
          e.printStackTrace(); 
         } 

        } 

        } catch (SQLiteException e) { 
        e.printStackTrace(); 
       } 

      } 
     }; 

     loading.start(); 
    } 

} 

而且Activity_One頁面上此註銷按鈕

imgBtn_LogOut.setOnClickListener(new View.OnClickListener() { 
      @Override 
      public void onClick(View v) { 
       File database = getApplicationContext().getDatabasePath(dbhelper.DATABASE_NAME); 

       if (!database.exists()) { 
        Log.e("Database", "Not Found"); 
       } else { 
        Log.e("Database", "Found"); 
        ctx.deleteDatabase(dbhelper.DATABASE_NAME); 
        Log.e("Database", " Deleted Completeley !!!"); 

        File dir = new File(Environment.getExternalStorageDirectory() + "classnkk_images"); 
        DeleteRecursive(dir); 

        Intent i = new Intent(Filter_Screen.this, Login_Screen.class); 
        i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); 
        i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); 
        startActivity(i); 
        finish(); 
       } 
      } 
     }); 
+0

當您按下注銷按鈕你有什麼logcat的輸出???它輸出「Log.e(」數據庫「,」發現「);」和「Log.e(」Database「,」Deleted Completeley !!!「);」 – RajSharma

+0

Log.e(「Database」,「Deleted Completeley !!!」);「 –

回答

0

我認爲這個問題是當你啓動應用程序中刪除數據庫後,它會自動創建新的數據庫沒有數據。

那麼請再次檢查數據庫創建與否?

我建議你保存共享首選項中的參數,並在啓動畫面中檢查它。它更好!