2015-11-13 76 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

我认为这个问题是当你启动应用程序中删除数据库后,它会自动创建新的数据库没有数据。

那么请再次检查数据库创建与否?

我建议你保存共享首选项中的参数,并在启动画面中检查它。它更好!