Reputation: 499
I have this in last activity where is inserted into database:
btnFinish = (Button) findViewById(R.id.btnFinish);
btnFinish.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Bundle extras = getIntent().getExtras();
if (extras != null) {
Name = getIntent().getExtras().getString("Name");
Email = getIntent().getExtras().getString("Email");
Phone = getIntent().getExtras().getString("Phone");
}
new SummaryAsyncTask().execute((Void) null);
startActivity(getIntent());
}
});
Currently when I click on btnfinish
is reload the same activity. What I want is to back to some activity. Not previous but some activity.. Is that possible?
Upvotes: 0
Views: 82
Reputation: 7560
The following code snippet is enough
Intent toSomeActivity=new Intent(CurrentActivity.this,SomeActivity.class);
intent.putExtra("Name",Name);
intent.putExtra("Email",Email);
intent.putExtra("Phone",Phone);
startActivity(toSomeActivity);
Upvotes: 1
Reputation: 7306
You need to define the Activity class where you want to redirect it. You have written
startActivity(getIntent());
which means the same Activity, will definitely reloads the same activity.
Change it to :
startActivity(new Intent(ThisActivityName.this, NetxActivtiy.class));
Hope it helps ツ
Upvotes: 1
Reputation: 28823
Currently when I click on btnfinish is reload the same activity. What I want is to back to some activity. Not previous but some activity.. Is that possible?
Your problem is this line:
startActivity(getIntent()); //getIntent returns intent that started this activity
So it just reloads that activity.
You would need to do:
Intent intent = new Intent(MyActivity.this, SomeActivity.class);
startActivity(intent);
Which will specify that you need to open SomeActivity
.
Hope it helps.
Upvotes: 1
Reputation: 7082
In your manifest, add this to your activity:
android:launchMode="singleTask"
With this parameter, each time your activity restarts, it will return to the same instance.
Upvotes: 1
Reputation: 414
You can get to any activity from where ever you are by simply calling the initiation of the activity you want to go to. try making a method for your button in your main and call it in the current method.
//the method in the main activity
public void homeButton()
{
HomeButton=(Button) findViewById(R.id.home_button);
HomeButton.setOnClickListener(new View.OnClickListener()
{
@Override
public void onClick(View v)
{
initHomeActivity();
}
});
}
...
//the activity initiation to be called by the onClick
public void initHomeActivity()
{
homeActivity = new HomeActivity(this);
homeActivity.init();
}
...
MainActivity mainActivity
//calling the method from the current activity
public void init() {
mainActivity.setContentView(R.layout.activity_sign_out);
mainActivity.homeButton();
}
Upvotes: 1