0

質問が繰り返されているようでしたら、お詫び申し上げます。しかし、私はまだこれで私を助けることができる答えやチュートリアルを見つけることができませんでした。

ユーザーがアプリケーションをインストールした後、一度ログインする必要があるアプリケーションを開発したい。したがって、ユーザーがアプリケーションを使用したい場合、ユーザーは再度ログインする必要はありません。アプリケーションにログインするには、ユーザーのデータをsqliteに保存する必要があります。

これについて私を助けることができるチュートリアルまたは何かですか?

前もって感謝します。

4

3 に答える 3

4

ステップ1:を作成Splash Activityし、アプリケーションへのエントリポイントとして使用します。NoDisplayを使用すると、ユーザーには表示されません。レイアウトは必要ありません

        <activity
        android:name="your.package.name.Splash"
        android:label="@string/app_name"
        android:theme="@android:style/Theme.NoDisplay" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>

ステップ2:Activityその中で、ユーザーがすでにログインしているかどうかを確認します。

    public class Splash extends Activity {

private SharedPreferences prefs;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    prefs = PreferenceManager
            .getDefaultSharedPreferences(getApplicationContext());
    if (!prefs.getBoolean("UserLoggedIn", false)) {

        startActivity(new Intent(this, UserLoginActivity.class));
        finish();

    } else {
        startActivity(new Intent(this, YourActivity.class));
        finish();
    }

}

       }

ユーザーがログインActivityするために使用する場合、値を作成しboolean、ログインの完了後にtrueに設定します(例)。

            ..........
           prefs = PreferenceManager
                    .getDefaultSharedPreferences(UserLoginActivity.this);
            Editor editor = prefs.edit();
            editor.putBoolean("UserLoggedIn", true);

            editor.commit();
            startActivity(new Intent(UserLoginActivity.this,
                    NextActivity.class));

これが使用例ですSharedPreferences

于 2013-03-24T14:16:19.803 に答える
3

これを参照してください: 共有設定を使用したAndroidユーザーセッション管理

コードサンプルがあり、必要な情報がすべて含まれています。また、質問で説明した内容のデータをSQLiteに保存する必要はありません。共有設定を使用するだけです。


幸運を!

于 2013-03-24T14:06:01.820 に答える
0
    Ok then open a database like this 

    public SQLiteDatabase sampleDB;
        public String COLUMN_ID="_id";
        public String COLUMN1="username";
        public String COLUMN2="password";
        public String TABLE_NAME="Androdata";

        @Override
        protected void onCreate(Bundle savedInstanceState) {

            super.onCreate(savedInstanceState);
            setContentView(R.layout.login);


            sampleDB =  this.openOrCreateDatabase(TABLE_NAME, MODE_PRIVATE, null);
            boolean x=init(TABLE_NAME);// init is a function that checks db and return 
                                                 //false only for 1st time
            if(x==false)
            {
            createDB();
            insertDB();
            }

            }
    public boolean init(String tableName)
        {
            Cursor cursor = sampleDB.rawQuery("select DISTINCT tbl_name from sqlite_master where tbl_name = '"+tableName+"'", null);
            if(cursor!=null) {
                if(cursor.getCount()>0) {
                                    cursor.close();
                    return true;
                }
                            cursor.close();
            }
            return false;
        }
        private void insertDB() {
            sampleDB.execSQL("INSERT INTO " +
                    TABLE_NAME +
                    " Values ('0','Androviewer','viewer');");   
            System.out.println("Inserted data successfully....");
        }
        private void createDB() {
            sampleDB.execSQL("CREATE TABLE IF NOT EXISTS " +
                    TABLE_NAME+ "(" + COLUMN_ID
                    + " integer primary key autoincrement, " + COLUMN1
                    + " text not null,"+ COLUMN2
                    + " text not null);");
            System.out.println("Database created successfully....");
        }


    enter default value for id as 0 which is done here in insert function.

then all you need to do is just insert entered value in to database ok 

all the best

    check in start screen if its 0 open register page and get the values in to database otherwise go to app as your wish 
于 2013-03-24T14:19:53.627 に答える