如何从服务类android显示共享意图

时间:2015-01-18 11:33:49

标签: android android-intent service share

我有一个服务类。我需要通过Facebook,whatsapp,gmail,yahoo等分享我的一些细节。但是当我尝试分享意图时我收到错误

  

android.util.AndroidRuntimeException:从中调用startActivity()   在Activity上下文之外需要FLAG_ACTIVITY_NEW_TASK   旗。这真的是你想要的吗?

以下是我的代码

shareIntent = new Intent(Intent.ACTION_SEND);
shareIntent.setType("text/plain"); 
startActivity(Intent.createChooser(shareIntent,"Share via"));
shareIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
Log.e("clicked","clicked>>>>>>share");

请给我一个解决方案

1 个答案:

答案 0 :(得分:0)

  

以下是我的代码

addFlags()之前致电startActivity()

  

所以在服务类上有一个布局

这对于服务来说是非典型的。