I am working on a registration form. It is the application's second page after the splash screen, which shows a login form and two buttons: login and signup. When we click on signup, it has a signup Form with two buttons: signup and exit.
When the user enters for first time he needs to login or signup, and when 'signup' is pressed, the registration process will start. The user has to provide a username, password, email address, and a mobile number. Once he fills in all this information, he can signin with the username and password.
All of this part is working fine, but my requirement is that after registration, the signup(activity) and login(activity) are deactivated once my application restarts with splash and MainActivity. So what do I have to do to make that work? Can any one help me with this?
How can I deactivate my LoginActivity and SignUpActivity which start with splashActivity and once register start with splash and main Activity again start with splash.
SplashActivity
public class SplashScreen extends Activity {
private long splashDelay = 5000; //5 seconds
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.splash_screen);
TimerTask task = new TimerTask()
{
@Override
public void run() {
finish();
Intent mainIntent = new Intent().setClass(SplashScreen.this, LoginActivity.class);
startActivity(mainIntent);
}
};
Timer timer = new Timer();
timer.schedule(task, splashDelay);
}
}
Login:
public class LoginActivity extends Activity {
Intent i;
Button signin, signup;
CheckBox check;
String name = "", pass = "";
byte[] data;
HttpPost httppost;
StringBuffer buffer;
HttpResponse response;
HttpClient httpclient;
InputStream inputStream;
SharedPreferences app_preferences;
List<NameValuePair> nameValuePairs;
EditText editTextId, editTextP;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.login);
signin = (Button) findViewById(R.id.signin);
signup = (Button) findViewById(R.id.signup);
editTextId = (EditText) findViewById(R.id.editTextId);
editTextP = (EditText) findViewById(R.id.editTextP);
app_preferences = PreferenceManager.getDefaultSharedPreferences(this);
check = (CheckBox) findViewById(R.id.check);
String Str_user = app_preferences.getString("username", "0");
String Str_pass = app_preferences.getString("password", "0");
String Str_check = app_preferences.getString("checked", "no");
if (Str_check.equals("yes")) {
editTextId.setText(Str_user);
editTextP.setText(Str_pass);
check.setChecked(true);
}
}
public void Move_to_next()
{
final Handler handle = new Handler();
Runnable delay = new Runnable() {
public void run() {
startActivity(new Intent(LoginActivity.this, SplashActivity.class));
finish();
}
};
handle.postDelayed(delay,2000);
}
public void Move_next()
{
startActivity(new Intent(LoginActivity.this, SignUpActivity.class));
finish();
}
@SuppressLint("NewApi")
private class LoginTask extends AsyncTask <Void, Void, String>
{
@SuppressLint("NewApi")
@Override
protected void onPreExecute()
{
super.onPreExecute();
// Show progress dialog here
}
@Override
protected String doInBackground(Void... arg0) {
try {
httpclient = new DefaultHttpClient();
httppost = new HttpPost("http://xxx/login1.php");
// Add your data
nameValuePairs = new ArrayList<NameValuePair>(2);
nameValuePairs.add(new BasicNameValuePair("UserEmail", name.trim()));
nameValuePairs.add(new BasicNameValuePair("Password", pass.trim()));
httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
// Execute HTTP Post Request
response = httpclient.execute(httppost);
inputStream = response.getEntity().getContent();
data = new byte[256];
buffer = new StringBuffer();
int len = 0;
while (-1 != (len = inputStream.read(data))) {
buffer.append(new String(data, 0, len));
}
inputStream.close();
return buffer.toString();
}
catch (Exception e)
{
e.printStackTrace();
}
return "";
}
@SuppressLint("NewApi")
@Override
protected void onPostExecute(String result) {
super.onPostExecute(result);
// Hide progress dialog here
if (buffer.charAt(0) == 'Y') {
Toast.makeText(LoginActivity.this, "login successfull", Toast.LENGTH_SHORT).show();
Move_to_next();
} else {
Toast.makeText(LoginActivity.this, "Invalid Username or password", Toast.LENGTH_SHORT).show();
}
}
}