Reputation: 502
I am working on android and this shows up on all devices, emulator and physical in every version I've tested. The transitions from screen to screen are all the same except when you go to the home screen from anywhere. Here is the fragment code.
public class NavBarFragment extends Fragment implements View.OnClickListener{
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View v = inflater.inflate(R.layout.nav_bar_frag, container, false);
Button homeButton = (Button) v.findViewById(R.id.homeButton);
Button vaultButton = (Button) v.findViewById(R.id.vaultButton);
Button shopButton = (Button) v.findViewById(R.id.shopButton);
Button accInfoButton = (Button) v.findViewById(R.id.accInfoButton);
homeButton.setOnClickListener(this);
vaultButton.setOnClickListener(this);
shopButton.setOnClickListener(this);
accInfoButton.setOnClickListener(this);
return v;
}
@Override
public void onClick(View v) {
Intent intent = null;
switch (v.getId()) {
case R.id.homeButton:
intent = new Intent(getActivity(), TasksScreenActivity.class);
break;
case R.id.vaultButton:
intent = new Intent(getActivity(), ChestActivity.class);
break;
case R.id.shopButton:
intent = new Intent(getActivity(), ShopActivity.class);
break;
case R.id.accInfoButton:
intent = new Intent(getActivity(), AccountActivity.class);
break;
default:
System.err.println("Error onClick in NavBarFragment");
break;
}
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
// intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
// intent.addFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION);
startActivity(intent);
}
}
and here is the relevant portion of the manifest
<activity android:name=".TasksScreenActivity"
android:launchMode="singleTask">
</activity>
<activity android:name=".ChestActivity"
android:launchMode="singleTask">
</activity>
<activity android:name=".ShopActivity"
android:launchMode="singleTask">
</activity>
<activity android:name=".AccountActivity"
android:launchMode="singleTask">
</activity>
As far as I can tell, I do everything the same on all of them, it should be consistent. For all the other screens, the animation shows a fade in like it pops up and for the home page it shows a fade out like it shrinks into the middle then goes away.
My problem is, they are inconsistent, I don't care what the end transition is as long as they are all the same.
Upvotes: 1
Views: 468
Reputation: 3523
You can use default animation,
Intent intent = new Intent(activity, clazz);
activity.startActivity(intent);
activity.overridePendingTransition(android.R.anim.slide_in_left, android.R.anim.slide_out_right);
Upvotes: 4
Reputation: 2182
Provided answer is correct, but you can also do like below if you don't want any animation while activity transition.
Intent intent = new Intent(activity, clazz);
activity.startActivity(intent);
activity.overridePendingTransition(0, 0);
It might help when no animation required.
Upvotes: 4
Reputation: 174
Intent intent = new Intent(activity, clazz);
activity.startActivity(intent);
activity.overridePendingTransition(R.anim.slide_in_right, R.anim.slide_out_left);
Use overridePendingTransition to set transition for all new viewing activity
Upvotes: 5