[英]How to call void method in onPostExecute() in doInBackground in Android?
I'm implementing power point to JPEG in Android. 我正在Android中将Power Point实现为JPEG。 I have to use
AsychTask
and doINBackground
. 我必须使用
AsychTask
和doINBackground
。 But I don't how to call understand my void method of saveSlideAs
in my Document class in onPostExecute()
method. 但我不如何调用理解我的无效方法
saveSlideAs
在我的文档类onPostExecute()
方法。
Here is my code: 这是我的代码:
SaveSlideAs() this method in Document Class
public void saveSlideAs(String outputPath, int slideNumber,
ImageFormat imageFormat)// Returns 100x100 image
{
try {
String strURI = Product.getBaseProductUri() + "/slides/"
+ fileName + "/slides/" +
Integer.toString(slideNumber) + "?format=imageFormat.toString().toLowerCase();
String signedURI = Utils.sign(strURI);
InputStream responseStream = Utils.processCommand(signedURI,"GET");
Folder.saveStreamToFile(outputPath,responseStream);
responseStream.close();
}
catch (Exception e) {
logger.error(e.getMessage());
}
}
doInBackground() method in StorageFolderUploadFile class
private void convertToImage()
{
httpGetAsynchTask httpGetAsyncTask = new httpGetAsynchTask();
httpGetAsyncTask.execute();
}
class httpGetAsynchTask extends AsyncTask<String , Integer , Object>
{
protected void onPreExecute()
{
try
{
dialog.setMessage("Please Wait");
dialog.show();
}
catch(Exception e)
{
}
}
protected String doInBackground(String... arg0)
{
// TODO Auto-generated method stub
Folder obj = new Folder();
try
{
response = obj.uploadFile(path);
Log.e("response ",": "+response);
if (response)
{
Document docObj=new Document( fileName);
count = docObj.getSlideCount();
if (count > 0)
{
for(int i=1; i <= count ; i++)
{
String outputPath = fileName + "_Slide" + i + ".jpg" ;
slideNumber = i;
Document docObj2=new Document(fileName);
docObj2.saveSlideAs(outputPath.toString().trim(), slideNumber, imageFormat);
}
}
}
}
catch (Exception e)
{
// TODO Auto-generated catch block
e.printStackTrace();
Log.e("",""+e.toString());
}
return null;
}
public void onPostExecute(String values)
{
try
{
if (response)
{
//here result is a text view
result.append("File Uploaded Successfully \n" + count);
if(dialog.isShowing())
{
dialog.dismiss();
}
}
else
{
result.append("Oops..Something went wrong");
}
}
catch(Exception e)
{
e.printStackTrace();
}
}
}
button click event
btnSubmit.setOnClickListener(new View.OnClickListener()
{
@Override
public void onClick(View arg0)
{
// TODO Auto-generated method stub
convertToImage();
}
});
You can access an instance of an outer class from within an inner class with the this
notation as such: 您可以使用
this
表示法从内部类内部访问外部类的实例:
public class Main {
public static void main(String[] args) {
Main main = new Main();
}
public void doThisInsideTheInnerClass() {
System.out.println("Hi there!");
}
public Main() {
class Inside {
public void insideVoid() {
Main.this.doThisInsideTheInnerClass();
}
}
Inside object = new Inside();
object.insideVoid();
}
}
So if the name of the outer class is Outer
, use Outer.this.saveSlideAs(...)
. 因此,如果外部类的名称为
Outer
,则使用Outer.this.saveSlideAs(...)
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.