Main Activity
package com.example.share1;
import android.app.Activity;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;
import android.os.Bundle;
import android.view.View;
import android.widget.EditText;
import android.widget.Toast;
public class MainActivity extends Activity {
private EditText uname;
private EditText upass;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
SharedPreferences prf1 = getApplicationContext().getSharedPreferences("abc", 0);
boolean isLogin=prf1.getBoolean("islogin", false);
getui();
if(isLogin==true)
{
Intent intent=new Intent(MainActivity.this,MainActivity1.class);
startActivity(intent);
}}
public void getui()
{
uname=(EditText) findViewById(R.id.editText1);
upass=(EditText) findViewById(R.id.editText2);
}
public void Registeration(View v)
{
Intent obj = new Intent(MainActivity.this, MainActivity1.class);
startActivity(obj);
}
public void Login(View v)
{
SharedPreferences prf = getApplicationContext().getSharedPreferences("xyz", 0);
String un=prf.getString("un", "");
String up=prf.getString("up", "");
if(un.equalsIgnoreCase(uname.getText().toString())&& up.equalsIgnoreCase(upass.getText().toString()))
{
Toast.makeText(getApplicationContext(), "Login", Toast.LENGTH_LONG).show();
SharedPreferences prf1 = getApplicationContext().getSharedPreferences("abc", 0);
Editor edit = prf1.edit();
edit.putBoolean("islogin", true);
edit.commit();
}
else
{
Toast.makeText(getApplicationContext(), "Login failed", Toast.LENGTH_LONG).show();
}
}
}
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;
import android.os.Bundle;
import android.view.View;
import android.widget.EditText;
import android.widget.Toast;
public class MainActivity extends Activity {
private EditText uname;
private EditText upass;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
SharedPreferences prf1 = getApplicationContext().getSharedPreferences("abc", 0);
boolean isLogin=prf1.getBoolean("islogin", false);
getui();
if(isLogin==true)
{
Intent intent=new Intent(MainActivity.this,MainActivity1.class);
startActivity(intent);
}}
public void getui()
{
uname=(EditText) findViewById(R.id.editText1);
upass=(EditText) findViewById(R.id.editText2);
}
public void Registeration(View v)
{
Intent obj = new Intent(MainActivity.this, MainActivity1.class);
startActivity(obj);
}
public void Login(View v)
{
SharedPreferences prf = getApplicationContext().getSharedPreferences("xyz", 0);
String un=prf.getString("un", "");
String up=prf.getString("up", "");
if(un.equalsIgnoreCase(uname.getText().toString())&& up.equalsIgnoreCase(upass.getText().toString()))
{
Toast.makeText(getApplicationContext(), "Login", Toast.LENGTH_LONG).show();
SharedPreferences prf1 = getApplicationContext().getSharedPreferences("abc", 0);
Editor edit = prf1.edit();
edit.putBoolean("islogin", true);
edit.commit();
}
else
{
Toast.makeText(getApplicationContext(), "Login failed", Toast.LENGTH_LONG).show();
}
}
}
Main Activity 1
package com.example.share1;
import android.app.Activity;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.EditText;
import android.widget.Toast;
public class MainActivity1 extends Activity {
EditText uname;
EditText upass;
CheckBox ch;
Button ok;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main_activity1);
}
public void getui() {
uname = (EditText) findViewById(R.id.editText1);
upass = (EditText) findViewById(R.id.editText2);
ok =(Button)findViewById(R.id.button1);
}
public void Registered(View v) {
String name1 = uname.getText().toString();
String pass1 = upass.getText().toString();
if(name1.replace(" ","").length()==0 || pass1.replace(" ","").length()==0)
{
Toast.makeText(getApplicationContext(), "enter values", Toast.LENGTH_LONG).show();
}
else
{
SharedPreferences prf = getApplicationContext().getSharedPreferences("xyz", 0);
Editor edit = prf.edit();
edit.putString("un",name1);
edit.putString("up", pass1);
edit.commit();
startActivity(new Intent(MainActivity1.this,MainActivity.class));
}
}
}
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.EditText;
import android.widget.Toast;
public class MainActivity1 extends Activity {
EditText uname;
EditText upass;
CheckBox ch;
Button ok;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main_activity1);
}
public void getui() {
uname = (EditText) findViewById(R.id.editText1);
upass = (EditText) findViewById(R.id.editText2);
ok =(Button)findViewById(R.id.button1);
}
public void Registered(View v) {
String name1 = uname.getText().toString();
String pass1 = upass.getText().toString();
if(name1.replace(" ","").length()==0 || pass1.replace(" ","").length()==0)
{
Toast.makeText(getApplicationContext(), "enter values", Toast.LENGTH_LONG).show();
}
else
{
SharedPreferences prf = getApplicationContext().getSharedPreferences("xyz", 0);
Editor edit = prf.edit();
edit.putString("un",name1);
edit.putString("up", pass1);
edit.commit();
startActivity(new Intent(MainActivity1.this,MainActivity.class));
}
}
}
Main Activity 2
package com.example.share1;
import android.app.Activity;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.view.View;
public class MainActivity2 extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main_activity2);
}
public void logout(View v)
{
SharedPreferences prf1 = getApplicationContext().getSharedPreferences(
"abc", 0);
prf1.edit().clear().commit();
Intent intent=new Intent(MainActivity2.this,MainActivity.class);
startActivity(intent);
}
}
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.view.View;
public class MainActivity2 extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main_activity2);
}
public void logout(View v)
{
SharedPreferences prf1 = getApplicationContext().getSharedPreferences(
"abc", 0);
prf1.edit().clear().commit();
Intent intent=new Intent(MainActivity2.this,MainActivity.class);
startActivity(intent);
}
}
No comments:
Post a Comment