android-asynctask

app:dexDebug - UNEXPECTED TOP-LEVEL EXCEPTION - on AsyncTask

允我心安 提交于 2019-12-24 14:02:59
问题 Oh how I hate this error. I'm getting the dreaded dexDebug error, but this time around I have no idea how to fix it. The exact error is: Information:Gradle tasks [:app:assembleDebug] :app:preBuild UP-TO-DATE :app:preDebugBuild UP-TO-DATE :app:checkDebugManifest :app:preReleaseBuild UP-TO-DATE :app:prepareComAndroidSupportAppcompatV72221Library UP-TO-DATE :app:prepareComAndroidSupportSupportV42300Library UP-TO-DATE :app:prepareDebugDependencies :app:compileDebugAidl UP-TO-DATE :app

Add listener in AsyncTask when called postExecute

拥有回忆 提交于 2019-12-24 13:54:06
问题 I have a AsyncTask class. here is code. private class WaitSec extends AsyncTask<Void, Void, Boolean>{ @Override protected Boolean doInBackground(Void... params) { try { Thread.sleep(2000); } catch (InterruptedException e) { e.printStackTrace(); } if(CheckSomeUtil.isItOk()) { return true; } else { return false; } } @Override protected void onPostExecute(Boolean aBoolean) { if(aBoolean) // in this line. is i want to set listener. super.onPostExecute(aBoolean); } } When called onPostExecute

Synchronizing data between SQLite (Android) and MS-SQL (Hosting)

我们两清 提交于 2019-12-24 13:52:57
问题 I need to Synchronize some tables between the App SQLite Database an a MS SQL Database hosted online. I already have a COLUMN (IsSync) on each table that allows me to know which ROWS are pending sync (i.e. SELECT * FROM Locations WHERE IsSync=0) The Locations table is one of the tables that I need to synchronize as soon as the table got updated/inserted. This table contains GPS Location data (Lat,Lng,Accuracy,Speed, etc) that is inserted EACH AND EVERY 3-4 SECONDS (15 records each minute).

Android: AsyncTask, my 1st task has not finished when the other starts

元气小坏坏 提交于 2019-12-24 13:23:23
问题 Here's my code in my main thread myAsyncRunnable mar = new myAsyncRunnable(GameActivity.this); mar.execute("fire"); PhotoTask photoTask = new PhotoTask(camera,surfaceCamera,isPreview,holder,GameActivity.this); photoTask.execute(null); in myAsyncRunnable.fire() I have a loop that changes 10 times the image of an ImageView in gameActivity. I want the photoTask to start when the last image has been changed @Override protected Void doInBackground(String... params) { fire(); return null; } public

AsyncTask executes but only sometimes

淺唱寂寞╮ 提交于 2019-12-24 11:54:07
问题 So i use this code to call my AsyncTask Log.d("before","make_connection"); new Make_Connection().execute(); Log.d("after","make_connection"); My class private class Make_Connection extends AsyncTask<Void,Void,String>{ final int port = 4445; @Override protected void onPreExecute() { Toast.makeText(KeyboardActivity.this,"This runs",Toast.LENGTH_LONG).show(); } @Override protected String doInBackground(Void... params) { Log.d("Connection","Started"); Log.e("Connec","this runs"); try { socket =

Playing repeated AudioTrack in android activity

守給你的承諾、 提交于 2019-12-24 11:37:53
问题 I want to play a tone pulse repeated at a specified rate, e.g. 3 times a second. It works about 20 times and then crashes as below. void playSound() { final AudioTrack audioTrack = new AudioTrack(AudioManager.STREAM_MUSIC, sampleRate, AudioFormat.CHANNEL_CONFIGURATION_MONO, AudioFormat.ENCODING_PCM_16BIT, generatedSnd.length, AudioTrack.MODE_STATIC); audioTrack.write(generatedSnd, 0, generatedSnd.length); audioTrack.play(); } In an asynctask I run a continuous loop that checks the time and

How to retain progress bar state while switching the fragments?

戏子无情 提交于 2019-12-24 11:27:33
问题 I have a navigation drawer where these many options are present Image material Video Material Audio Material We are maintaining separate fragment for each material and every fragment have grid view in which we are populating thumbnail of that material. Once user click on the thumbnail a full material will be downloaded(Using AsyncTask). I am displaying the progress bar over the thumbnail while downloading the full material. Now here i stuck to a problem that suppose progress bar is showing 20

Access instance variables from an activity inside a AsyncTask

南楼画角 提交于 2019-12-24 11:25:15
问题 I have an AsyncTask (in a separate file) which is invoked on an activity. When I instantiate the AsyncTask, I send the activity as a param. How can I access the acitivity's instance variables from the onPostExecute method of the AsyncTask? Thanks! 回答1: You must be careful when passing an Activity or Context to an AsyncTask that is not an inner (non-static) class of an Activity - this is because in this case the lifetime of the Activity / Context and the AsyncTask are different, and if you

Passing functions into a global AsyncTask Android

被刻印的时光 ゝ 提交于 2019-12-24 10:58:39
问题 I'm trying to create a global actions file in which i can call certain functions globally anywhere within the app. so far i have got it working with functions etc but now what i'm wanting to do is put a standard AsyncTask into my global actions and pass it functions/voids from my Activity so i'd want to pass it a function to run in background and a function to run once finished. does anyone know how do this? and also advise me on running multiple functions on a background thread do i create

Android WebView: how to load page after javascript execution

随声附和 提交于 2019-12-24 09:36:45
问题 Relating to this SO question, I want to remove the notifications as well as the flicker that occurs when displaying TeX in a WebView in android. I tried the AsyncTask method, to preload the page and then "download" it, before loading the data into the WebView but I'm stuck on an IllegalStateException: Target host must not be null, or set in parameters. This error is coming from the following code: protected String doInBackground(String... url) { String r = ""; try { HttpClient hc = new