2015-11-19 241 views
-2

我正在開發一個Android應用程序,我在啓動屏幕上使用手機號註冊。我想要的只是在安裝應用程序時,註冊應該只需要一次和第一次。安裝應用程序後,應用程序應從另一個活動打開,而不是從啓動屏幕打開。如何可能。如何從兩個活動啓動一個Android應用程序

+0

您需要添加SharedPrefrence「http://www.tutorialspoint.com/android/android_shared_preferences.htm」來存儲所需的信息。當應用第二次打開時,您需要檢查sharedPrefrence的值。 – Naitik

+0

此鏈接顯示錯誤「找不到頁面」 –

+0

照片添加一些代碼? –

回答

0

在splash類中,您應該檢查應用程序是否第一次運行。如果是,繼續,如果沒有,則開始第二個活動。可以通過檢查布爾值,將其存儲在共享首選項中,並且每次在啓動時檢查其值。

0

嘗試使用SharedPrefrence.But它不是完整的答案。顯示您的SplashScreen檢查您的用戶是否註冊。

 Boolean REG_RESPONCE = new Session_manag(getActivity()).IsSessionCheckOrCreated(); 
      if (REG_RESPONCE.equals(true)) { 
       Intent toHomeactivity = new Intent(Splash.this, MainMenu.class); 
       finish(); 
       startActivity(toHomeactivity); 
      } else { 

       Intent i = new Intent(Splash.this, SignUp.class); 
       finish(); 
       startActivity(i); 
      } 
0

這太容易處理。你需要的是一個如何實現這個概念。所以我給你的路線圖,做一些在互聯網上搜索我要告訴你的事情。這些步驟如下

  1. 我認爲這樣做的簡單方法是實現共享首選項。共享喜好是什麼?他們會將您的客戶信息存儲到應用程序中,例如他的姓名,密碼
  2. 因此,當Spalsh首先檢查共享首選項中是否有值時,如果有值,則表示您的用戶已經登錄
  3. 如果用戶沒有存儲任何值,那麼這意味着您需要將他帶到註冊活動。
  4. 所以用這種方式你可以把你的用戶放在你想要的地方。但是沒有辦法同時使用兩項活動。

您可以閱讀herethis的共享偏好設置,這是一個不錯的教程,幫助您入門。

4

成功註冊登錄後,您必須將數據存儲在SharedPreferences中。

AppTypeDetails是SharedPreferences的類。

AppTypeDetails.getInstance(SignUpActivity.this).setEmail(<Your Email ID>); 
AppTypeDetails.getInstance(SignUpActivity.this).setPassword(<Your Password>); 

AppTypeDetails.java

import android.content.Context; 
import android.content.SharedPreferences; 
import android.preference.PreferenceManager; 

public class AppTypeDetails { 

    private SharedPreferences sh; 

    private AppTypeDetails() { 

    } 

    private AppTypeDetails(Context mContext) { 
     sh = PreferenceManager.getDefaultSharedPreferences(mContext); 
    } 

    private static AppTypeDetails instance = null; 

    /** 
    * 
    * @param mContext 
    * @return {@link AppTypeDetails} 
    */ 
    public synchronized static AppTypeDetails getInstance(Context mContext) { 
     if (instance == null) { 
      instance = new AppTypeDetails(mContext); 
     } 
     return instance; 
    } 

    // get username 
    public String getEmail() { 
     return sh.getString("email", ""); 
    } 

    public void setEmail(String email) { 
     sh.edit().putString("email", email).commit(); 
    } 

    // get password 
    public String getPassword() { 
     return sh.getString("password", ""); 
    } 

    public void setPassword(String password) { 
     sh.edit().putString("password", password).commit(); 
    } 

    public void clear() { 
     sh.edit().clear().commit(); 
    } 

} 

現在檢查下面的代碼在啓動畫面。

String email = AppTypeDetails.getInstance(SplashScreen.this).getEmail(); 
String pass = AppTypeDetails.getInstance(SplashScreen.this).getPassword(); 

if (email.trim().isEmpty() && pass.trim().isEmpty()) { 
    Intent intent = new Intent(SplashScreen.this, Login.class); 
    startActivity(intent); 
} else { 
    Intent intent = new Intent(SplashScreen.this, MainScreenTabHost.class); 
    startActivity(intent); 
} 

爲了清楚SharedPreferences

呼叫上註銷clear()方法。

+0

感謝您的指導 –

+0

@MMartin如果我的回答對你有幫助,那麼接受我的回答。 –

0

您可以在啓動屏幕上檢查用戶是否已用數字簽名或不簽名的條件,因爲您必須在SharedPreferences中保存該數字。 按照thew下面的步驟,

第1步:當用戶打開應用程序首次啓動畫面會come.here您可以檢查條件number.At第一次,當用戶來到在App值(數)不到風度的存在SharedPreferences.so應用程序將要求輸入號碼。當用戶輸入號碼並提交時,將其存儲在SharedPreferences中。

第二步:現在,第二次當用戶進入啓動畫面時,由於SharedPreferences具有值(數字),所以該條件成爲真。因此您可以在第二項活動上重定向應用。

相關問題