user2129147
user2129147

Reputation:

How open same Activity inside itself?

I have a HomeActivity which displays a list of clothes and clicking in one of them opens DetailsActivity, which displays its details in the left side. In the right side I show a list of more clothes "you may like these as well:".

After clicking in one of these recommended clothes, I want to open another DetailsActivity on top of the current, and NOT replace its contents.

As so when the user presses the "Back" button, I want to unstack each clothe details before the HomeActivity.

How can I do that? I looked through all Intent flags and don't seen to find a way to do it.

-= UPDATED =-

I tried fragments instead of Activities but the stack of the fragments is lost when I rotate the screen.

FragmentDetails fDetails = new FragmentDetails();
Bundle args = new Bundle();
args.putInt(FragmentDetails.BILLING_ID, billingId);
fDetails.setArguments(args);
FragmentTransaction ft = getFragmentManager().beginTransaction();
ft.add(android.R.id.content, fDetails, UUID.randomUUID().toString());
ft.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE);
ft.addToBackStack(null);
ft.commit();

And this is the method to open the same Activity, which is not working:

Intent intent = new Intent(this, ActivityDetails.class);
intent.putExtra(ActivityDetails.BILLING_ID, billingId);
startActivity(intent);

Upvotes: 0

Views: 432

Answers (1)

Sharjeel
Sharjeel

Reputation: 15798

You should be handling this some other way like swapping fragment or just updating view with new data (cloth detail) instead of reopening Activity.

If you really have to then you can start new Activity and finish old one.

startActivity(yourIntent);
finish();

This way if user presses back, application will go way to main view.

Upvotes: 1

Related Questions