小编Srh*_*rht的帖子

并行执行多个AsyncTask

我正在使用Android SDK 4.0.3 API15,我希望并行运行多个AsyncTasks.我从Web服务器获取数据并实时动画(10 fps).但是根据用户操作,我还需要将一些数据发送到Web服务器.当发生这种情况时,我的动画暂停一小段时间(发送数据进入队列并获取数据等待它完成)因此我无法捕捉实时.

这个答案很有说服力,但我无法使其发挥作用.所以任何帮助都将非常感激.

我想我需要使用这个功能来实现:

AsyncTask.executeOnExecutor(Executor exec, Params... params)
Run Code Online (Sandbox Code Playgroud)

但我无法将执行程序作为参数传递,我无法实例化执行程序.这是我的AsyncTask类:

public class GetPlayers extends AsyncTask<String, Void, String> {
    @Override
    protected String doInBackground(String... urls) {

        Thread.currentThread().setPriority(Thread.MAX_PRIORITY);

        rawData="";
        for (String url : urls) {
            DefaultHttpClient client = new DefaultHttpClient();
            HttpGet httpGet = new HttpGet(url);
            try {
                HttpResponse execute = client.execute(httpGet);
                InputStream content = execute.getEntity().getContent();

                BufferedReader buffer = new BufferedReader(new InputStreamReader(content));
                if((rawData = buffer.readLine()) == null){
                    rawData = "error";
                }

            } catch (Exception e) {
                e.printStackTrace();
            }
        }
        return …
Run Code Online (Sandbox Code Playgroud)

parallel-processing android android-asynctask

29
推荐指数
1
解决办法
4万
查看次数

向用户提供Excel(xlsx)文件以便在Django(Python)中下载

我正在尝试使用Django创建和提供excel文件.我有一个jar文件,它获取参数并根据参数生成一个excel文件,它没有问题.但是,当我试图获取生成的文件并将其提供给用户下载时,文件就会破碎.它的大小为0kb.这是我用于excel生成和服务的代码片段.

def generateExcel(request,id):
    if os.path.exists('./%s_Report.xlsx' % id):
        excel = open("%s_Report.xlsx" % id, "r")
        output = StringIO.StringIO(excel.read())
        out_content = output.getvalue()
        output.close()
        response = HttpResponse(out_content,content_type='application/vnd.openxmlformats-officedocument.spreadsheetml.sheet')
        response['Content-Disposition'] = 'attachment; filename=%s_Report.xlsx' % id
        return response
    else:
        args = ['ServerExcel.jar', id]
        result = jarWrapper(*args) # this creates the excel file with no problem
        if result:
            excel = open("%s_Report.xlsx" % id, "r")
            output = StringIO.StringIO(excel.read())
            out_content = output.getvalue()
            output.close()
            response = HttpResponse(out_content,content_type='application/vnd.openxmlformats-officedocument.spreadsheetml.sheet')
            response['Content-Disposition'] = 'attachment; filename=%s_Report.xlsx' % id
            return response
        else:
            return HttpResponse(json.dumps({"no":"excel","no one": "cries"}))
Run Code Online (Sandbox Code Playgroud)

我搜索了可能的解决方案并尝试使用File …

python django excel xlsx stringio

7
推荐指数
3
解决办法
1万
查看次数

在自定义视图中设置背景图像

我创建了一个扩展 View 类的类。

public class SplashScreen extends View
Run Code Online (Sandbox Code Playgroud)

我通过设置 contentview 来使用它

View splash = new SplashScreen(this);
setContentView(splash);
Run Code Online (Sandbox Code Playgroud)

我需要设置背景图片,但我不能使用布局。我想我需要画画布,但我不知道该怎么做。

protected void onDraw(Canvas canvas) {
  ballBounds.set(ballX-ballRadius, ballY-ballRadius, ballX+ballRadius, ballY+ballRadius);
  paint.setColor(Color.LTGRAY);
  // canvas.drawImage(R.drawable.background_image); (Ps: I know there is no function such as drawImage)"
  canvas.drawOval(ballBounds, paint);}
Run Code Online (Sandbox Code Playgroud)

android view background-image

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