Sandeep Gupta
Sandeep Gupta

Reputation: 45

How to switch between Activities using the same Fragment?

I am using an Action Bar, with Fragments. I want to switch Activity on Action-Item click event.

I make an Intent Another Activity, on click event. But when another Activity gets invoked, it comes with a new screen. While I am using the same layout.xml in setcontentView in both of the Activities.

I want to switch Activity, while staying on the same screen.

Since I have used Fragments programmatically, replace fragment on switching Activity.

Upvotes: 0

Views: 197

Answers (2)

YFeizi
YFeizi

Reputation: 1528

You can try this :

if (getActivity() instanceof YourActivity){
// do something
}else{
//do something else 
}

Upvotes: 0

Chandrakanth
Chandrakanth

Reputation: 3831

If you provide same layout for two activities then also it will shows like new screen. Because if you start new activity the new instance of the activity will be created and new screen will come and if any default activity transition animation is there that will be applied to the new activity.

Upvotes: 1

Related Questions