Reputation: 2063
I'm creating Android application using Xamarin, AppCompat v4 and v7 packages (Xamarin.Android.Support.v7.AppCompat.23.0.1.3). I need to reverse scene transition animation when I finish with the second activity pressing back button. I found a solution here. So, I'm using FinishAfterTransition
method in overriden OnBackPressed
in a class derived from Android.Support.V7.App.AppCompatActivity
:
public class BaseToolbarActivity : AppCompatActivity
{
public override void OnBackPressed()
{
base.OnBackPressed();
FinishAfterTransition();
}
}
When I press the back button in an activity subclassed from BaseToolbarActivity
I get the following error.
10-20 12:41:13.815 E/AndroidRuntime( 9557): FATAL EXCEPTION: main
10-20 12:41:13.815 E/AndroidRuntime( 9557): Process: GetTruck.ClientApp, PID: 9557
10-20 12:41:13.815 E/AndroidRuntime( 9557): java.lang.NoSuchMethodError: no method with name='finishAfterTransition' signature='()V' in class Landroid/app/Activity;
10-20 12:41:13.815 E/AndroidRuntime( 9557): at md5b2985d08cc2bafff83c57ef84572ed3f.CreateOrderActivity.n_onCreate(Native Method)
10-20 12:41:13.815 E/AndroidRuntime( 9557): at md5b2985d08cc2bafff83c57ef84572ed3f.CreateOrderActivity.onCreate(CreateOrderActivity.java:28)
10-20 12:41:13.815 E/AndroidRuntime( 9557): at android.app.Activity.performCreate(Activity.java:5411)
10-20 12:41:13.815 E/AndroidRuntime( 9557): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
10-20 12:41:13.815 E/AndroidRuntime( 9557): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2396)
10-20 12:41:13.815 E/AndroidRuntime( 9557): at android.app.ActivityThread.access$800(ActivityThread.java:139)
10-20 12:41:13.815 E/AndroidRuntime( 9557): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1293)
10-20 12:41:13.815 E/AndroidRuntime( 9557): at android.os.Handler.dispatchMessage(Handler.java:102)
10-20 12:41:13.815 E/AndroidRuntime( 9557): at android.os.Looper.loop(Looper.java:149)
10-20 12:41:13.815 E/AndroidRuntime( 9557): at android.app.ActivityThread.main(ActivityThread.java:5257)
10-20 12:41:13.815 E/AndroidRuntime( 9557): at java.lang.reflect.Method.invokeNative(Native Method)
10-20 12:41:13.815 E/AndroidRuntime( 9557): at java.lang.reflect.Method.invoke(Method.java:515)
10-20 12:41:13.815 E/AndroidRuntime( 9557): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:817)
10-20 12:41:13.815 E/AndroidRuntime( 9557): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:633)
10-20 12:41:13.815 E/AndroidRuntime( 9557): at dalvik.system.NativeStart.main(Native Method)
No matter in what order I call methods inside OnBackPressed
my app crashes anyway. I also tried to rebuild the project, call FinishAfterTransition
in other methods, all the same. Googling tells me nothing. It seems like I'm the only person on Earth who has come across this error. What am I doing wrong?
Upvotes: 1
Views: 528
Reputation: 2139
FinishAfterTransition is actually an Activity (not AppCompatActivity) method that is only in API 21 and above (http://developer.android.com/reference/android/app/Activity.html#finishAfterTransition()) therefore if you run the app in anything less than API 21, you'll run into that error because it doesn't exist.
Unfortunately because it is not part of the AppCompatActivity, you'll have to find another solution to achieve the result you want (or only call it on API >= 21).
Hope that helps!
Upvotes: 1