views:

351

answers:

4

Is it possible to define the transition between two activities for Android 1.5 and better? I would like an activity to fade in.

+1  A: 

You can do this with Activity.overridePendingTransition(). You can define simple transition animations in an XML resource file. A good tutorial on this can be found here.

iandisme
Thanks iandisme. overridePengingTransition is API level 5. Is it not possible to do this for level 3 (Android 1.5)?
hgpc
Ah, you're right. CaseyB's answer is probably more along the lines of what you're looking for.
iandisme
Haven't found yet how to do a proper fade in with CaseyB's answer.
hgpc
+2  A: 

Yes. You can tell the OS what kind of transition you want to have for your activity.

@Override
public void onCreate(Bundle savedInstanceState)
{
    super.onCreate(savedInstanceState);
    getWindow().setWindowAnimations(ANIMATION);

    ...

}

Where ANIMATION is an integer referring to a built in animation in the OS.

CaseyB
Do I have to do something else for it to work? getWindow().setWindowAnimations(android.R.anim.fade_in) doesn't result in the push transition that was used by default, but it's not a fade transition either. The new activity just appears over the previous one in a Nexus One device.
hgpc
That's because this isn't asking for a resource, it's asking for the id of a transition animation built into the OS. http://developer.android.com/intl/fr/reference/android/view/Window.html#setWindowAnimations(int)
CaseyB
Can you provide an example? I can't find the constant. Thanks.
hgpc
It seems setWindowAnimations only accepts style resources. getWindow().setWindowAnimations(android.R.style.Animation_Toast) is the closest I've found to a fade in, but it fades from black, not the previous activity.
hgpc
A: 

You cannot use overridePendingTransition in Android 1.5. overridePendingTransistion came to Android 2.0.

If you're gonna go through this without any error you have to compile for the target (1.5 or higher) using the ordinary animations (or you own) or you have to compile for the target (2.0 or higher) using overridePendingTransistion.

Summary: You cannot use overridePendingTransistion in Android 1.5.

You can though use the built-in animations in the OS.

Julian Assange
That is not correct. Animations are in Android well before 1.6 and you can use overridePendingTransistion with reflection to still target 1.5.
hgpc
Well, my mistake. Updated my post. You can surely do your own animations and customizing them as you want in 1.5. But you can still not use overridePendingTransition since it started to appear in API-level 5.
Julian Assange
A: 

What about animations written manually by code? can I use them as setWindowsAnimations?

oriharel