Context wants FLAG_ACTIVITY_NEW_TASK but I've already set that flag

后端 未结 3 694
粉色の甜心
粉色の甜心 2020-12-07 01:19

I\'ve created a common re-usable class for the company I work for to create some common interface elements.

The class, takes in a single parameter as in the constru

相关标签:
3条回答
  • 2020-12-07 01:50

    I fixed it adding the flag to the Chooser Intent

    Intent sharingIntent = new Intent(android.content.Intent.ACTION_SEND)
                .setType("text/plain")
                .putExtra(android.content.Intent.EXTRA_SUBJECT, "Subject Here")
                .putExtra(android.content.Intent.EXTRA_TEXT, url)
                .addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    
    context.startActivity(Intent.createChooser(sharingIntent, "Share with").addFlags(Intent.FLAG_ACTIVITY_NEW_TASK));
    
    0 讨论(0)
  • Problem has been fixed, I think this is simply the case of an "order of operation" scenario

    heres what allowed this thing to work:

        ll.setOnClickListener(new OnClickListener() {
    
            public void onClick(View v) {
    
    
    
                if(chooser) {
                    Intent intent = Intent.createChooser(i, "Complete With");
                    intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                    mContext.startActivity(intent);
                } else
                    mContext.startActivity(i);
    
            }
        });
    

    also added a "final" modifier to the parameter in the method declaration

    public LinearLayout ContentClickableRowWithIcon(Drawable icon, String title, final Intent i, final Boolean chooser)
    
    0 讨论(0)
  • 2020-12-07 02:07

    Actually your exception mean that you are using Not Activity Context. it could be called from Application context. Check that you are in Activity context since this is not a service

    0 讨论(0)
提交回复
热议问题