相关疑难解决方法(0)

Android中的背景图片下载需要帮助吗?

我有一个图像视图,我写过刷卡,在刷卡的时候,图像从互联网上下载,所以我想我必须在刷卡之前在后台下载图像,因为我需要使用asynctask或Service或IntentService,所有这些都有助于下载和存储在数据/数据/ mypackages中,但仍然在我的情况下刷卡任何想法,也告诉我哪一个是最好的,是我正在以正确的方式调用

asynctask

2.服务

3.意向服务如下图所示,

我很困惑哪一个是正确的方法,因为我的问题仍未解决

这是asynctask代码示例代码段

public class Demo extends Activity {

  @Override

  public void onCreate(Bundle savedInstanceState) {

    super.onCreate(savedInstanceState);

    setContentView(R.layout.main);

       new FirstTask().execute(); // calling Asynctask here

  }
Run Code Online (Sandbox Code Playgroud)

}

异步任务代码

private class FirstTask extends AsyncTask<Void, Void, Void> {
        private final ProgressDialog dialog = new ProgressDialog(Catalogue.this);
        int temp = 0;

        // can use UI thread here
        protected void onPreExecute() {
            this.dialog.setMessage("Loading...");
            this.dialog.setCancelable(false);
            //this.dialog.show();
            System.gc();
            Toast.makeText(Catalogue.this, "My Async  Created",
                    Toast.LENGTH_LONG).show();
        }

        @Override
        protected Void doInBackground(Void... params) {
            Looper.prepare();  
            try {

                myddownloadmethod();// …
Run Code Online (Sandbox Code Playgroud)

service android android-asynctask intentservice

14
推荐指数
2
解决办法
2万
查看次数