2014-03-14 24 views
2

我有一个OnCreateActionMenu分享我的values.I'm使用ShareContentprovider方法我通过意图传递值。但问题是我想获得在AsynTask运行的值。所以,如果它可能使用goto like语句?或者其他方式? 我的代码是Ascreask与OnCreate操作菜单

​​

其中t1是从生成的textFieldAsynTask

回答

1

当你不得不mShareActionProvider对象的引用,你随时都可以更改其份额的意图。

可以执行你ASyncTask和完成后,您可以设置shareIntent再次使用这样的事情:

public boolean onPostExecute(String newString) { 

    //newString here is the calculated String in ASyncTask 
    mShareActionProvider.setShareIntent(getDefaultShareIntent(newString)); 

} 

private Intent getDefaultShareIntent(String newText) { 
    // TODO Auto-generated method stub 

    Intent intent = new Intent(Intent.ACTION_SEND); 
    intent.setType("text/plain"); 
    // passing the username 
    intent.putExtra(Intent.EXTRA_SUBJECT,""+name+"via Myapp"); 
    // passing ID 
    intent.putExtra(Intent.EXTRA_TEXT,newText); 
    return intent; 
} 
+1

它的作品:)非常感谢 – Sukan

+0

没有。快乐的编码。 :) – tasomaniac

0

值的AsyncTask有一个称为onProgressUpdate()API。使用这个你可以发送间歇过程值回UI线程。

保护无效onProgressUpdate(进展...值)

在API级别publishProgress之后的UI线程(进度...)3 下运行时调用。指定的值是传递给publishProgress(Progress ...)的值。

保护的最后无效publishProgress(进展...值)

Added in API level 3 
This method can be invoked from doInBackground(Params...) to publish updates on the UI thread while the background computation is still running. Each call to this method will trigger the execution of onProgressUpdate(Progress...) on the UI thread. onProgressUpdate(Progress...) will not be called if the task has been canceled. 
+1

是啊,但如何的我值发送到意向getDefaultShareIntent()方法? – Sukan

+0

您可以在onProgressUpdate()内调用您的函数getDefaultShareIntent(),并使用适当的值。 onProgressUpdate中的代码在UI线程上运行。 – Sushil