asynctask

Android: Writing to a file in AsyncTask

匿名 (未验证) 提交于 2019-12-03 09:18:39
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 由 翻译 强力驱动 问题: I would love to be able to write to a local directory in my AsyncTask subclass, but I can't seem to figure out how to use getFilesDir(), since I cannot, to my knowledge, create an instance of ContextWrapper and Context in this subclass. So, what have I tried? I've tried getting the files directory the only way I know how by attempting many different things to create instances of Context and ContextWrapper in order to access the getFilesDir() method. That's it. That's all I know how to do. I'm probably missing a lot of blatantly

How to use AsyncTask inside instantiateItem method of PagerAdapter

匿名 (未验证) 提交于 2019-12-03 09:05:37
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I wanted to use ViewPager to display some encrypted images. For that I created an extension of PagerAdapter and put my decryption code inside instantiateItem method. But the problem is that the process of decryption takes too long. So, I used AsyncTask inside instantiateItem method to show a progress dialog. Now, ViewPager displays a blank screen at first and I should swipe to view the first image. Moreover setCurrentItem() does not work. My Code: public class FullScreenImageAdapter extends PagerAdapter { private Activity _activity; private

Android SQLite Columns … are not unique

匿名 (未验证) 提交于 2019-12-03 09:05:37
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I am using SQLite on android and am getting this error 02-11 18:05:37.224: E/SQLiteDatabase(26583): android.database.sqlite.SQLiteConstraintException: columns name, foreign_word are not unique (code 19) However, this is called right after onUpgrade() is called, so there should be nothing in the database itself. This is the SQL Statement used : private static final String CREATE_DB_TB_2 = "CREATE TABLE " + TABLE_VOCAB_WORDS + "(" + COLUMN_NAME + " TEXT NOT NULL," + COLUMN_WORD_FOREIGN + " TEXT NOT NULL," + COLUMN_WORD_ENGLISH + " TEXT NOT

AsyncTask is not cancelling the long running operation in android

匿名 (未验证) 提交于 2019-12-03 08:54:24
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 由 翻译 强力驱动 问题: I have to download huge amount of data from server. It is taking minimum 10 seconds to download. Here is my code to download using asyntask class. And I want to cancel the downloading operation unconditionally if the user clicks on home button while downloading operation is going on. The problem is... I'am executing cancel() method but it is not cancelling the downloading operation. I'am seeing that operation is running in background in logcat view even i came out of application. I just want to stop the execution of doInBackground(

When would Activity's instance die?

匿名 (未验证) 提交于 2019-12-03 08:46:08
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 由 翻译 强力驱动 问题: Here is a sample code which make me a little missing: package com . leak ; import android . app . Activity ; import android . app . ProgressDialog ; import android . os . AsyncTask ; import android . os . Bundle ; public class WindowLeakActivity extends Activity { @Override protected void onCreate ( Bundle savedInstanceState ) { super . onCreate ( savedInstanceState ); new LeakThread (). execute (); } class LeakThread extends AsyncTask < Void , Void , Void >{ ProgressDialog dialog ; @Override protected void onPreExecute () { dialog

JSoup doesn&#039;t work with AsyncTask

匿名 (未验证) 提交于 2019-12-03 08:30:34
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I noticed one interesting thing with my app ( I use Jsoup inside AsyncTask) After that my app crashed. LogCat is: 12-15 11:16:43.023: I/dalvikvm(371): Could not find method org.jsoup.Jsoup.connect, referenced from method com.example.myexample.MainActivity$MyTask.doInBackground 12-15 11:16:43.033: W/dalvikvm(371): VFY: unable to resolve static method 3462: Lorg/jsoup/Jsoup;.connect (Ljava/lang/String;)Lorg/jsoup/Connection; 12-15 11:16:43.033: D/dalvikvm(371): VFY: replacing opcode 0x71 at 0x0003 12-15 11:16:43.033: D/dalvikvm(371): VFY: dead

How one interface can be used for different background android tasks?

匿名 (未验证) 提交于 2019-12-03 07:50:05
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: Well, I have an activity class with two background task (Async-Task) which have been defined in two separate classes like public class GettingBeaconsList extends AsyncTask public class GettingAirports extends AsyncTask which are initialized and executed in MainClass public class MainClass extends Activity implements DelegateTaskCompleted { int ServiceBoolean = 0; public OnClickListener LoadingBeaconList = new OnClickListener() { public void onClick(View v) { ServiceBoolean =1; new GettingBeaconsList (context,MainClass.this).execute(); } }

Android 异步处理AsyncTask

前提是你 提交于 2019-12-03 06:31:58
AsyncTask 和Handler对比 1 ) AsyncTask实现的原理,和适用的优缺点 AsyncTask,是android提供的轻量级的异步类,可以直接继承AsyncTask,在类中实现异步操作, 并 提供接口反馈当前 异步执行的程度 (可以通过接口实现UI进度更新),最后反馈执行的结果给UI主线程. 使用的优点: l 简单,快捷 l 过程可控 使用的缺点 : l 在使用多个异步操作和并需要进行Ui变更时,就变得复杂起来. 2 )Handler异步实现的原理和适用的优缺点 在Handler 异步实现时,涉及到 Handler, Looper, Message,Thread四个对象,实现异步的流程是主线程启动Thread(子线程)àthread(子线程)运行并生成Message-àLooper获取Message并传递给HandleràHandler逐个获取Looper中的Message,并进行UI变更。 使用的优点: l 结构清晰,功能定义明确 l 对于多个后台任务时,简单,清晰 使用的缺点: l 在单个后台异步处理时,显得代码过多,结构过于复杂(相对性) AsyncTask介绍 Android的AsyncTask比Handler更轻量级一些,适用于简单的异步处理。 首先明确Android之所以有Handler和AsyncTask,都是为了不阻塞主线程(UI线程)

AsyncTask和Handler对比

≡放荡痞女 提交于 2019-12-03 06:12:09
AsyncTask和Handler对比 1 ) AsyncTask实现的原理,和适用的优缺点 AsyncTask,是android提供的轻量级的异步类,可以直接继承AsyncTask,在类中实现异步操作, 并 提供接口反馈当前 异步执行的程度 (可以通过接口实现UI进度更新),最后反馈执行的结果给UI主线程. 使用的优点: l 简单,快捷 l 过程可控 使用的缺点 : l 在使用多个异步操作和并需要进行Ui变更时,就变得复杂起来. 2 )Handler异步实现的原理和适用的优缺点 在Handler 异步实现时,涉及到 Handler, Looper, Message,Thread四个对象,实现异步的流程是主线程启动Thread(子线程)àthread(子线程)运行并生成Message-àLooper获取Message并传递给HandleràHandler逐个获取Looper中的Message,并进行UI变更。 使用的优点: l 结构清晰,功能定义明确 l 对于多个后台任务时,简单,清晰 使用的缺点: l 在单个后台异步处理时,显得代码过多,结构过于复杂(相对性) AsyncTask介绍 Android的AsyncTask比Handler更轻量级一些,适用于简单的异步处理。 首先明确Android之所以有Handler和AsyncTask,都是为了不阻塞主线程(UI线程)

AsyncTask execute() or executeOnExecutor()?

匿名 (未验证) 提交于 2019-12-03 02:46:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: What's the difference between using execute() and executeOnExecuter() ? How does execute() execute tasks by default? (in serial or in parallel?) What should be used for new SDKs >16? Is it a good practice to use parallel execution ( THREAD_POOL_EXECUTOR ) for tasks rather than serial even if it doesn't matter for the application or does that depends on the number of AsyncTask s that will be executed? 回答1: How does .execute execute tasks by default (in serial or in parallel). Before API level 11: parallel. API level 11 and up: serial. which