[mono-android] Corrected post - Cannot use StartActivity() from IAnimationListener
Jonathan Pryor
jpryor at novell.com
Tue Mar 15 14:58:22 EDT 2011
On Mar 15, 2011, at 2:44 PM, Michael Reynolds wrote:
> I am trying to convert the java code below to use it in my MonoDroid project.
>
> fade2.setAnimationListener(new AnimationListener() {
> public void onAnimationEnd(Animation animation) {
> // The animation has ended, transition to the Main Menu screen
> startActivity(new Intent(MySplashActivity.this, MyMenuActivity.class));
> MySplashActivity.this.finish()
> ;
> }
>
> I converted the Java code above to the C# code below:
>
> fade2.SetAnimationListener(new AnimationListener(this));
This is right.
> And the C# AnimationListener:
>
> private class AnimationListener : Activity, Animation.IAnimationListener
This isn't. Don't inherit from Activity, inherit from Java.Lang.Object:
private class AnimationListener : Java.Lang.Object, Animation.IAnimationListener
> {
> private readonly Context _context;
This should be an Activity; no point in forcing a runtime exception when we can check this at compile time...
>
> public AnimationListener(Context context)
Should also take an Activity.
> {
> _context = context;
> }
>
> public void OnAnimationEnd(Animation animation)
> {
> //The animation has ended, transition to the Main Menu screen
> StartActivity(new Intent(_context, typeof (QuizMenuActivity)));
Should thus be:
_context.StartActivity(new Intent(_context, typeof(QuizMenuActivity));
_context.Finish ();
Does that work for you?
- Jon
More information about the Monodroid
mailing list