Why is there a mistake?



  • I do that. startactivity

    public static void share(Context context) {
        Intent shareIntent = new Intent(Intent.ACTION_SEND);
        shareIntent.setType("text/plain");
        shareIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        shareIntent.putExtra(Intent.EXTRA_SUBJECT, context.getString(R.string.subject));
        shareIntent.putExtra(Intent.EXTRA_TEXT, context.getString(R.string.message) +
                " " + context.getString(R.string.google_play_url));
        context.startActivity(Intent.createChooser(shareIntent, context.getString(R.string.share_to)));
    }
    

    and fly out with such a mistake.

    FATAL EXCEPTION: main Process: com.fittingroom.newtimezone, PID: 10326 android.util.AndroidRuntimeException: Calling startActivity() from outside of an Activity context requires the FLAG_ACTIVITY_NEW_TASK flag. Is this really what you want? at android.app.ContextImpl.startActivity(ContextImpl.java:734) at android.app.ContextImpl.startActivity(ContextImpl.java:721) at android.content.ContextWrapper.startActivity(ContextWrapper.java:345) at comfittingroom.newtimezone.tools.UtilClass.share(UtilClass.java:428) at comfittingroom.newtimezone.activities.MainActivity$1.onItemClick(MainActivity.java:93) at commikepenz.materialdrawer.DrawerBuilder$5.onClick(DrawerBuilder.java:1716) at com.mikepenz.materialdrawe

    in line

    context.startActivity(Intent.createChooser(shareIntent, context.getString(R.string.share_to)));
    

    What's wrong?



  • The statues provide comprehensive information on the error:

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

    I'll move.

    Вызов startActivity() вне контекста другого Activity требует флаг FLAG_ACTIVITY_NEW_TASK. Вы это имели в виду?
    

    Put that flag in. Intentto make it work.


    There's a flag, but not the intent:

    Intent intent = Intent.createChooser(shareIntent, context.getString(R.string.share_to));
    intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    startActivity(intent);
    



Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2