Possible Duplicate:
Launching intent from a class outside an activity
I was just wondering can a intent be used from a POJO class or must it be used in one that extends Activity? If it can how would you implement if?
public class DataManager{
public DataManager (){}
public void get ()
{
Intent intent = new Intent (null,Webservice.class);
intent.putExtra("uri", "http://someuri/service/users/id/21001");
startActivity (intent);
}
}
Actually,
startActivity()is method of Activity class. Not any java class method. So to access this method in other pojo class you have to useContextof activity.You can do something like,
Update:
One thing to be noted is your Intent code line,
what is null ? You have to put reference of Activity class as a first parameter of Intent constructor. Just check it.
So the code line will be,