I am having a problem using the intent. As you can see below I have an intent under Log in, in which, if it is true, it will bring me to "HomePageActivity". The problem is, It doesn't let me go to "HomePageActivity". I'm pretty sure "HomePageActivity" is correct. This problem happens to all buttons at all activities. Nothing lets me to go back to my "HomePageActivity". This problem is easily fixed when I change "HomePageActivity" to some other activities and it will go to that activity. But I want to go to "HomePageActivity". Can anyone help me go home please?
This is the code to my "SignInActivity"
public class SignInActivity extends ActionBarActivity {
protected EditText mUsernameSignIn;
protected EditText mPasswordSignin;
protected Button mSignInButton;
protected Button mSignUpButton;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_sign_in);
//Initialize
mUsernameSignIn = (EditText) findViewById(R.id.usernameSignIn);
mPasswordSignin = (EditText) findViewById(R.id.passwordSignIn);
mSignInButton = (Button) findViewById(R.id.signinBtnSignIn);
mSignUpButton = (Button) findViewById(R.id.signupBtnSignIn);
//Listen to when the log in mSignIn Button is clicked
//Sign in the user using Parse SDK
mSignInButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
//get the user inputs from edit text and covert to string
String username = mUsernameSignIn.getText().toString().trim();
String password = mPasswordSignin.getText().toString().trim();
//Loging In
ParseUser.logInInBackground(username, password, new LogInCallback() {
@Override
public void done(ParseUser parseUser, com.parse.ParseException e) {
if (e == null) {
//Success!
Toast.makeText(SignInActivity.this, "Welcome Back", Toast.LENGTH_LONG).show();
//bring user to HomePageActivity
Intent GoHome = new Intent(SignInActivity.this, HomePageActivity.class);
startActivity(GoHome);
} else {
//Sorry, Sign in Failed!
AlertDialog.Builder builder = new AlertDialog.Builder(SignInActivity.this);
builder.setMessage(e.getMessage());
builder.setTitle("Sorry, Sign In Failed");
builder.setPositiveButton("ok", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int which) {
//close the dialog
dialogInterface.dismiss();
}
});
AlertDialog dialog = builder.create();
dialog.show();
}
}
});
}
});
//Go Sign Up
mSignUpButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent GoSignUp = new Intent(SignInActivity.this, RegisterActivity.class);
startActivity(GoSignUp);
}
});
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu_sign_in, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
//noinspection SimplifiableIfStatement
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
}
And this is the code to my "HomePageActivity"
public class HomePageActivity extends ActionBarActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_home_page);
// Enable Local Datastore.
Parse.enableLocalDatastore(this);
Parse.initialize(this, "EshgpTdW5ialGcLR7ing2x4jhkkgmbHBVeKwLh0J", "av66d87CSHlbRElTPPRx5jLWGefLYwfZ5Y4GHsZ6");
ParseObject testObject = new ParseObject("TestObject");
testObject.put("foo", "bar");
testObject.saveInBackground();
}
//add pet button brings to add pet activity
public void addPetBtn(View v) {
Intent intent = new Intent(HomePageActivity.this, AddPetActivity.class);
startActivity(intent);
}
//register button brings to registration activity
public void registerBtn(View v) {
Intent intent = new Intent(HomePageActivity.this, RegisterActivity.class);
startActivity(intent);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu_main, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
switch (id) {
case R.id.action_update:
//take user to update activity
break;
case R.id.action_log_out:
// take user to log out activity
ParseUser.logOut();
//take user back to Log in Screen
Intent GoHome = new Intent(HomePageActivity.this,SignInActivity.class);
startActivity(GoHome);
break;
}
return super.onOptionsItemSelected(item);
}
}
And this is the Android Manifest
<?xml version="1.0" encoding="utf-8"?>
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name=".HomePageActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".AddPetActivity"
android:label="@string/title_activity_add_pet" >
</activity>
<activity
android:name=".RegisterActivity"
android:label="@string/title_activity_register" >
</activity>
<activity
android:name=".SignInActivity"
android:label="@string/title_activity_sign_in" >
</activity>
</application>