Click here to Skip to main content
15,881,559 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
while calling a new intent from a non activity class
as
Java
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
Posted
Updated 1-Aug-13 1:00am
v2

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
Java
this.context.startActivity(new Intent(this.context,MyBig1.class));

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


/Fredrik
 
Share this answer
 
Comments
dare2dash 1-Aug-13 7:51am    
Thanx
I had tried that even this is not working.
it crashes out as soon as reaching to new intent place.
Fredrik Bornander 1-Aug-13 8:25am    
Crashing with what type of Exception?
Member 10192655 29-Sep-13 2:33am    
but, when I do the same in my application, the context is becoming null the point of startActivity(). Ultimately, the second class is not getting instantiated. I have declared my context as, " private Context context;"
Member 10192655 29-Sep-13 2:35am    
I am using this in a class, that extends a FileObserver, but neither an activity, nor a service.
Try..
Java
Intent myIntent = new Intent(mContext, MyBig1.class);
mContext.startActivity(myIntent);

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

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900