This question has already been answered:
- Why the error takes off? 1 reply
There is this class:
public class Share implements IShare { @Override public void share(List<File> data) { ArrayList<Uri> toShare = new ArrayList<>(); for(File f : data){ toShare.add(Uri.fromFile(f)); } Intent shareIntent = new Intent(); shareIntent.setAction(Intent.ACTION_SEND_MULTIPLE); shareIntent.putParcelableArrayListExtra(Intent.EXTRA_STREAM, toShare); shareIntent.setType("image/*"); Intent myChooser = Intent.createChooser(shareIntent, "Share pictures to: "); myChooser.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); MyApp.getContext().startActivity(myChooser); IHistoryManager hm = new HistoryManager(); hm.addToHistory(HistoryTypes.SENT, data); } } In which chooser flag is set FLAG_ACTIVITY_NEW_TASK, however, after starting the method, an exception is thrown:
Caused by: android.util.AndroidRuntimeException: Calling startActivity() from outside of an Activity context requires the FLAG_ACTIVITY_NEW_TASK flag. Is this really what you want? MyApp is a class inherited from Application; the static getContext () method returns a static variable with the application context:
public class MyApp extends Application { private static Context context; @Override public void onCreate() { super.onCreate(); context = getApplicationContext(); } public static Context getContext() { return context; } }