我想在定製微調使用分享按鈕FLAG_ACTIVITY_NEW_TASK標誌錯誤
這是我的代碼:
btnShareCS_One.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
// Share
// Share Selected Item In Cell-Phone
Intent sharingIntent = new Intent(android.content.Intent.ACTION_SEND);
sharingIntent.setType("text/plain");
String shareBody = txtTitleCS_One.getText().toString() + ": " + edtContentCS_One.getText().toString();
sharingIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, txtTitleCS_One.getText().toString());
sharingIntent.putExtra(android.content.Intent.EXTRA_TEXT, shareBody);
// sharingIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
// sharingIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
getContext().startActivity(Intent.createChooser(sharingIntent, "Share via"));
}
});
但不起作用 錯誤:
android.util.AndroidRuntimeException: Calling startActivity() from outside of an Activity context requires the FLAG_ACTIVITY_NEW_TASK flag. Is this really what you want?
如何修理它?
我的自定義微調正常工作,代碼工作正常,但不是在定製微調
我試着使用:
getContext().startActivity(Intent.createChooser(sharingIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK), "Share via"));
所以不要太工作
問候,它豆確定 – HK1988