Search code examples
androidrobotium

How do I fire an intent from Robotium


I need to fire an intent from Robotium and tried the following three methods. None of them worked. Could you please advise me?

//DOES NOT WORK ---
Intent intent = new Intent(Intent.ACTION_VIEW,Uri.parse("market://details?    id=com.readability"));
getInstrumentation().getContext().startActivity(intent);

//DOES NOT WORK
getInstrumentation().runOnMainSync(new Runnable() {
public void run() {
Intent intent = new Intent(Intent.ACTION_VIEW,Uri.parse("market://details?id=com.readability"));
}
});

//DOES NOT WORK
solo.getCurrentActivity().runOnUiThread(new Runnable() {
public void run() {
Intent intent = new Intent(Intent.ACTION_VIEW,Uri.parse("market://details?id=com.readability"));
getInstrumentation().getContext().startActivity(intent);
}
});

Solution

  • Calling startActivity() from outside of an Activity context requires the FLAG_ACTIVITY_NEW_TASK flag. Is this really what you want?

    If so, you can add this:

    intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);