从非活动类调用新意图 [英] calling new intent from non activity class
本文介绍了从非活动类调用新意图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
从非活动类调用新意图
为
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
。
而不是在动画的匿名实现中声明
,您应该从调用私有上下文
。 AnimationListeneranimlation.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 wrongcontext
.
Instead of declaringprivate Context context
in the anonymous implementation ofAnimation.AnimationListener
, you should referenceContext
from the class that callsanimlation.setAnimationListener
.
For this example I'll assume your class is calledMyClass
, 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屋!
查看全文