Here is the code of Password Activity that store Password in Sqlite , what actually I want when application is open for the first time then MainActivity will open when user save Password then next time whenever the application is open instead of MainActivity, login Activity will open for user login using password that is save last time. thanks in advance.
Password Activity
- using System;
- using System.Collections.Generic;
- using System.IO;
- using System.Linq;
- using System.Text;
- using Android.App;
- using Android.Content;
- using Android.OS;
- using Android.Runtime;
- using Android.Views;
- using Android.Widget;
- namespace PasswordManager
- {
- [Activity(Label = "Password")]
- public class Password : Activity
- {
- DataBase db;
- protected override void OnCreate(Bundle savedInstanceState)
- {
- base.OnCreate(savedInstanceState);
- SetContentView(Resource.Layout.Password);
- db = new DataBase();
- Button btnSave = FindViewById<Button>(Resource.Id.btnSave);
- btnSave.Click += BtnSave_Click;
- }
- public void PasswordSave()
- {
- var txtPassword1 = FindViewById<EditText>(Resource.Id.txtPassword1);
- var txtPassword2 = FindViewById<EditText>(Resource.Id.txtPassword2);
- string Pass1 = txtPassword1.Text.ToString();
- string pass2 = txtPassword2.Text.ToString();
- if (Pass1 == "" && pass2 == "")
- {
- Toast.MakeText(this, "Empty Fields", ToastLength.Short).Show();
- }
- else
- {
- if (Pass1 == pass2)
- {
- Person person = new Person()
- {
- password = Pass1,
- };
- db.insertIntoTable(person);
- Toast.MakeText(this, "Password Saved", ToastLength.Short).Show();
- }
- else
- {
- Toast.MakeText(this, "Please Enter the Same Password", ToastLength.Short).Show();
- }
- }
- }
Login Activity Code
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using Android.App;
- using Android.Content;
- using Android.OS;
- using Android.Runtime;
- using Android.Views;
- using Android.Widget;
- namespace PasswordManager
- {
- [Activity(Label = "Login")]
- public class Login : Activity
- {
- Person p;
- protected override void OnCreate(Bundle savedInstanceState)
- {
- base.OnCreate(savedInstanceState);
- SetContentView(Resource.Layout.Login);
- Button btnLogin = (Button)FindViewById(Resource.Id.btnLogin);
- btnLogin.Click += BtnLogin_Click;
- }
- private void BtnLogin_Click(object sender, EventArgs e)
- {
- var pass = FindViewById<EditText>(Resource.Id.txtPassword);
- string npass = pass.ToString();
- p = new Person();
- string mypass = p.password;
- if (npass == mypass)
- {
- Toast.MakeText(this, "Password Matched", ToastLength.Long).Show();
- StartActivity(typeof(MainActivity));
- }
- else
- {
- Toast.MakeText(this, "Password not Matched", ToastLength.Long).Show();
- }
- }
- }
- }