GVKun编程网logo

Android:无法为AsyncTask指定List返回类型:doInBackground(无法为sea of thieves执行启动程序)

16

在本文中,我们将给您介绍关于Android:无法为AsyncTask指定List返回类型:doInBackground的详细内容,并且为您解答无法为seaofthieves执行启动程序的相关问题,此外

在本文中,我们将给您介绍关于Android:无法为AsyncTask指定List返回类型:doInBackground的详细内容,并且为您解答无法为sea of thieves执行启动程序的相关问题,此外,我们还将为您提供关于Android - 启动页 “android:windowBackground” 变型?、Android AsyncTask 使用多线程是因为android 官网说的吗?、Android Studio调试forAsBackground代码的AsyncTask、android – asynctask doInBackgound()如果已经运行asynctask则不运行的知识。

本文目录一览:

Android:无法为AsyncTask指定List返回类型:doInBackground(无法为sea of thieves执行启动程序)

Android:无法为AsyncTask指定List返回类型:doInBackground(无法为sea of thieves执行启动程序)

我有以下基于asynctask的代码块.
我试图通过返回LoadFeed()返回一个List变量
并且doInBackground的返回类型是String.
如果我将doInBackground的返回类型从String更改为List
然后我收到一个错误

"The return type is incompatible with AsyncTask<String,Void,String>.doInBackground(String[])"

我该如何解决这个错误?
请帮忙

谢谢,

  private class dispData extends AsyncTask<String, Void, String> {
   private final ProgressDialog dialog = new ProgressDialog(MessageList.this);
   // can use UI thread here
   protected void onPreExecute() {
      dialog.setMessage("Fetching scores...");
      dialog.show();
   }


   // automatically done on worker thread (separate from UI thread)
   protected String doInBackground(final String... args) {
      return loadFeed();

   }


  // can use UI thread here
   protected void onPostExecute(final List<String> result) {
      if (dialog.isShowing()) {
         dialog.dismiss();
      }
     adapter = 
            new ArrayAdapter<String>(MessageList.this,R.layout.row,result);
     MessageList.this.setlistadapter(adapter);

   }
}

解决方法:

将您的班级定义更改为:

class dispData extends AsyncTask<String, Object, List<String>>

这将强制doInBackground声明成为:

protected List<String> doInBackground(String... arg);

Android - 启动页 “android:windowBackground” 变型?

Android - 启动页 “android:windowBackground” 变型?

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:drawable="@android:color/white" />
    <item>
        <bitmap
            android:gravity="bottom"
            android:scaleType="centerCrop"
            android:src="@drawable/bg_splash"
            android:tileMode="disabled" />
    </item>
</layer-list>
<style name="main_splash_activity_style" parent="Theme.AppCompat">
        <item name="android:windowBackground">@drawable/main_bitmap_splash_bg</item>
        <item name="android:windowFullscreen">true</item>
        <!--<item name="android:windowIsTranslucent">false</item>-->
        <!--<item name="windowActionBar">false</item>-->
        <!--<item name="android:windowDisablePreview">true</item>-->
        <!--<item name="android:windowContentOverlay">@null</item>-->
        <item name="windowNoTitle">true</item>
    </style>
<activity
            android:name=".activity.SplashActivity"
            android:screenOrientation="portrait"
            android:theme="@style/main_splash_activity_style">
</activity>

 

Android AsyncTask 使用多线程是因为android 官网说的吗?

Android AsyncTask 使用多线程是因为android 官网说的吗?

AsyncTask“touches”两个线程:Main/UI 和后台线程。它的方法很少在 Main/UI 线程 (onPre/onPostExecute()) 上运行,而一种方法在后台的 WorkerThread 上运行。这些方法之间存在内部同步/队列。

并发(async/await)不(必然)使用第二个线程,而是使用“CPU空闲的时刻”。想想这个非真实情况:如果 Main/UI 线程 100% 忙,那么在 Main/UIThread 有一些“空闲 CPU 周期”可以共享之前,不能执行任何并发。相反,在最后一个示例中,AsyncTasks 将异步执行其工作,而不考虑其他线程(其结果将排队到 UI/MainThread 以供稍后处理)。

Android Studio调试forAsBackground代码的AsyncTask

Android Studio调试forAsBackground代码的AsyncTask

我在AsyncTask类的doInBackground()代码中放了一些断点.但是当我调试应用程序时,控制不会超过doInBackground().请帮我解决这个问题.

解决方法

将以下代码片段放在doInBackground的开头:

android.os.Debug.waitForDebugger();

那么当你在该线程中设置断点时,eclipse会找到它.

在你的模拟器中,

>转到开发者设置.
>点击选择调试应用程序
>选择要调试的应用程序
>将启用“等待调试器”复选框.选中此复选框

现在再试一次运行该应用程序.

android – asynctask doInBackgound()如果已经运行asynctask则不运行

android – asynctask doInBackgound()如果已经运行asynctask则不运行

当用户登录我的应用程序时.我正在启动一个asynctask来维护用户会话.并且异步任务无限期地运行直到用户注销.我的问题是,当我尝试启动其他asynctasks时,他们的doInBackground()方法永远不会被执行.

我在某处读到,如果异步任务已在运行,我们就无法启动新的异步任务.我可以确认这一点,因为当我删除用户会话异步任务时,它正常工作.有解决方法吗?

P.S.:我已经使用了executeOnExecutor()方法.但它没有帮助.

解决方法

对于可能长时间运行的操作,我建议您使用Service而不是asynctask.

用户登录时启动服务

Intent i= new Intent(context,YourService.class);
i.putExtra("KEY1","Value to be used by the service");
context.startService(i);

并在用户注销时停止服务

stopService(new Intent(this,YourService.class));

要了解有关服务的更多信息,您可以参考此处

Service : Android developers

Service : Vogella

要了解有关asynctask vs service的更多信息,请参阅此内容

Android: AsyncTask vs Service

When to use a Service or AsyncTask or Handler?

关于Android:无法为AsyncTask指定List返回类型:doInBackground无法为sea of thieves执行启动程序的问题就给大家分享到这里,感谢你花时间阅读本站内容,更多关于Android - 启动页 “android:windowBackground” 变型?、Android AsyncTask 使用多线程是因为android 官网说的吗?、Android Studio调试forAsBackground代码的AsyncTask、android – asynctask doInBackgound()如果已经运行asynctask则不运行等相关知识的信息别忘了在本站进行查找喔。

本文标签: