Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Switching between activities: Don't hide previous activity

Fairly straightforward question here, but I can't seem to find someone who has asked this already. Most likely not using the right keywords.

In any case, here is my scenario:

I am launching a new activity in which I show a web view. I have called overridePendingTransition in order to get the animation I want when I switch to the new activity, which works fine (at least, the animation part works fine). However, there are a couple things which take away from the effect.

What I want is to have the webview slide over the previous activity, from the bottom, and when the user presses back, it should slide back down out of site. The second part of this works like a charm, but the first part isn't exactly what I want.

Immediately upon triggering the new activity, the old one is hidden, and in its place is blackness, so it looks like the webview slides over blackness. I would like to have it leave the previous activity in the background instead of hiding it, so the webview slides over that. Is this possible?

Thanks!

like image 746
Droidmon Avatar asked Jun 25 '12 19:06

Droidmon


People also ask

How do I go back to previous activity on android?

Android activities are stored in the activity stack. Going back to a previous activity could mean two things. You opened the new activity from another activity with startActivityForResult. In that case you can just call the finishActivity() function from your code and it'll take you back to the previous activity.

How do you end an intent?

On Clicking the back button from the New Activity, the finish() method is called and the activity destroys and returns to the home screen.


1 Answers

I came here looking for the same thing but the current answers were no help. I hope this helps, being four months after the question was asked!

In my opinion, this is due to a bug in the Android platform because:

  • it only happens if the exitAnim is 0,
  • it only happens with 'translate' elements. 'alpha' elements (fade-in, fade-out) work fine.

Here is my workaround:

@Override
protected void onResume() {
    overridePendingTransition(R.anim.mu_slide_in_left, R.anim.mu_no_anim);
    super.onResume();
}

@Override
protected void onPause() {
    overridePendingTransition(0, R.anim.mu_slide_out_right);
    super.onPause();
}

Where mu_no_anim.xml is

<?xml version="1.0" encoding="utf-8"?>
<alpha xmlns:android="http://schemas.android.com/apk/res/android"
   android:interpolator="@android:anim/accelerate_interpolator"
   android:fromAlpha="1.0" android:toAlpha="1.0" android:duration="100000" />

So this is forcing the out-going activity to stay visible by specifying the reliable alpha mechanism to fade it from alpha 1 to alpha 1 over 100 seconds - in otherwords, just keep it fully visible.

The workaround isn't completely perfect. For example, if your new Activity is called from a Dialog, the Dialog will look as if it is dismissed as the Activity slides into place - but it will be back again after closing that Activity.

like image 90
Myles Bennett Avatar answered Sep 18 '22 06:09

Myles Bennett