从非活动类调用新意图 [英] calling new intent from non activity class

查看:75
本文介绍了从非活动类调用新意图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

从非活动类调用新意图



 animlation.setAnimationListener( new  Animation.AnimationListener(){

private 上下文上下文;

@覆盖
public void onAnimationEnd(动画)动画){
// TODO自动生成的方法存根
.context.startActivity( new Intent( this 。 context,MyBig1。 class ));
}

@ Override
public void onAnimationRepeat(动画动画){
// TODO自动生成的方法存根
}

@覆盖
public void onAnimationStart(动画动画){
// TODO自动生成的方法存根
}
} );



给出错误

MyBig1.class 具有 MyBig1的构造函数(上下文context); 什么是解决方案

解决方案

这对你不起作用,因为你引用了错误的 context

而不是在动画的匿名实现中声明私有上下文。 AnimationListener ,您应该从调用 animlation.setAnimationListener 的类中引用 Context 。 />


对于这个例子,我会假设您的类名为 MyClass ,然后您应该更改来自

  this  .context.startActivity( new  Intent( this  .context,MyBig1 。 class )); 



to

 MyClass。 this  .context.startActivity( new  Intent(MyClass。这个 .context,MyBig1。 class )); 





/ Fredrik


试试..

意图myIntent =  new  Intent(mContext,MyBig1。 class ); 
mContext.startActivity(myIntent);



或者,请参阅..

http://stackoverflow.com/questions/12319631/issue-starting-activity-from-non-activity-class [ ^ ]


while calling a new intent from a non activity class
as

animlation.setAnimationListener(new Animation.AnimationListener(){

  private Context context;

  @Override
  public void onAnimationEnd(Animation animation) {
    // TODO Auto-generated method stub
    this.context.startActivity(new Intent(this.context,MyBig1.class));
  }

  @Override
  public void onAnimationRepeat(Animation animation) {
    // TODO Auto-generated method stub
  }

  @Override
  public void onAnimationStart(Animation animation) {
    // TODO Auto-generated method stub
  }
});


giving error
as MyBig1.class has Constructor with MyBig1(Context context); what is the solution

解决方案

That won't work for you as you're referencing the wrong context.
Instead of declaring private Context context in the anonymous implementation of Animation.AnimationListener, you should reference Context from the class that calls animlation.setAnimationListener.

For this example I'll assume your class is called MyClass, and you should then change the call from

this.context.startActivity(new Intent(this.context,MyBig1.class));


to

MyClass.this.context.startActivity(new Intent(MyClass.this.context,MyBig1.class));



/Fredrik


Try..

Intent myIntent = new Intent(mContext, MyBig1.class);
mContext.startActivity(myIntent);


Or,See..
http://stackoverflow.com/questions/12319631/issue-starting-activity-from-non-activity-class[^]


这篇关于从非活动类调用新意图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆