Java 在安装android应用程序后创建一次登录页面供首次使用

Java 在安装android应用程序后创建一次登录页面供首次使用,java,android,sqlite,login,android-sqlite,Java,Android,Sqlite,Login,Android Sqlite,如果我的问题似乎是重复的,我道歉。但是,我仍然找不到任何答案或教程,可以帮助我在这方面 我想开发一个应用程序,需要在用户安装应用程序后登录一次。因此,如果用户想要使用应用程序,则无需再次登录。用户的数据需要存储在sqlite中,以便登录到应用程序 是否有任何教程或任何东西可以帮助我在这方面 提前感谢。请参阅: 它有代码示例,并包含您所需的所有有用信息。对于您在问题中描述的内容,无需将数据存储在SQLite中。只需使用共享首选项即可 祝你好运 步骤1:创建一个启动活动,并将其用作应用程序的入口点

如果我的问题似乎是重复的,我道歉。但是,我仍然找不到任何答案或教程,可以帮助我在这方面

我想开发一个应用程序,需要在用户安装应用程序后登录一次。因此,如果用户想要使用应用程序,则无需再次登录。用户的数据需要存储在sqlite中,以便登录到应用程序

是否有任何教程或任何东西可以帮助我在这方面


提前感谢。

请参阅:

它有代码示例,并包含您所需的所有有用信息。对于您在问题中描述的内容,无需将数据存储在SQLite中。只需使用共享首选项即可



祝你好运

步骤1:创建一个
启动活动
,并将其用作应用程序的入口点。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>
在用户用于登录的
活动中,创建一个
布尔值,并在登录完成后将其设置为true(示例):


这是一个使用
SharedReferences

的示例,您不认为仅用于管理登录用户的数据库有点过于复杂吗?共享参考会做得很好这是她的愿望,melati要求db,这就是为什么我发布了这篇文章不是我的愿望:)可能是主题启动者之一,尽管他似乎不太了解在Android中保存数据的方法:)是的,两个都在这里。选择任何用户希望的内容。谢谢你们。我是android的初学者。我也不太确定当用户为我开发时该如何开发。
    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 
            ..........
           prefs = PreferenceManager
                    .getDefaultSharedPreferences(UserLoginActivity.this);
            Editor editor = prefs.edit();
            editor.putBoolean("UserLoggedIn", true);

            editor.commit();
            startActivity(new Intent(UserLoginActivity.this,
                    NextActivity.class));
    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