ui-thread

SQLite query run on UI thread with ExpandableListView/SimpleCursorTreeAdapter

笑着哭i 提交于 2019-12-04 14:55:36
I'm in the progress of developing an Android app for displaying a number of RSS feeds (yes, I know there are many apps like this already). The data to be displayed is backed by a content provider, and I want to be backward compatible with API level 4. I'm using an ExpandableListView to display the content of three different RSS feeds. The ExpandableListView 's adapter is implemented as a sub-class of SimpleCursorTreeAdapter : private class RssFeedLatestListAdapter extends SimpleCursorTreeAdapter { public static final String FEED_NAME_COLUMN = "feedName"; public RssFeedLatestListAdapter(Context

Avoiding the window (WPF) to freeze while using TPL

為{幸葍}努か 提交于 2019-12-03 21:19:53
I am building a WPF which has a button that execute a sql query in sql server (the query could take a long time to run). I want to use TPL for doing that. This code: var result = Task.Factory.StartNew(() => { command.ExecuteNonQuery(); }); gives this exception: ExecuteNonQuery requires an open and available Connection. The connection's current state is closed. I guess this is due to the fact that the query runs on a different thread and is not aware of the open connection. I have 2 questions: 1. How do I make the new thread know of this open connection? 2. After solving this ,How do I get the

android addView in background thread

若如初见. 提交于 2019-12-03 13:29:36
问题 I need to add lots of views in a loop, while this fragment does that, the app will also have a navigation drawer and action bar where the user can do things. so I would like this process to not a) slow down the app by blocking the user, b) preferably add the views in a background thread. The dilemma is that I think android doesn't like views to be added in a non-UI thread, so is there a best practice for this? I plan to have a progress bar view object visible in the fragment's view while the

How to know if this thread is a UI Thread

放肆的年华 提交于 2019-12-03 11:53:15
问题 Is there any way on Android to know, if the thread running my code, is the UI Thread or not ? In swing there was SwingUtilities.isEventDispatchThread() to tell me if i am on the UI Thread, or not. Is there any function in the Android SDK that lets me know this ? 回答1: Answer borrowed from here: How to check if current thread is not main thread Looper.myLooper() == Looper.getMainLooper() Any Android app has only one UI thread, so you could somewhere in the Activity callback like onCreate()

Is a good practice create anonymous AsyncTask for parallel small known freeze process? [closed]

最后都变了- 提交于 2019-12-03 08:37:33
问题 Closed . This question is opinion-based. It is not currently accepting answers. Want to improve this question? Update the question so it can be answered with facts and citations by editing this post. Closed 5 years ago . E.g.: you gonna do something that will take a few seconds and don't wanna freeze your UI thred, right? You could use an AsyncTask but you don't wanna create a external (or inner) class to solve a small freeze problem. So, is a good pratice do it? package com.example

OperationQueue.main vs DispatchQueue.main

女生的网名这么多〃 提交于 2019-12-03 08:27:28
问题 When you need to perform something on the main thread in the completion block of a networking task or an operation, which of these ways to get it would be the most appropriate and why?: OperationQueue.main.addOperation DispatchQueue.main.async 回答1: For details on the differences between the two types of queue, see Lion's answer. Both approaches will work. However, NSOperation is mostly needed when more advanced scheduling (including dependencies , canceling , etc.) is required. So in this

android addView in background thread

佐手、 提交于 2019-12-03 03:34:21
I need to add lots of views in a loop, while this fragment does that, the app will also have a navigation drawer and action bar where the user can do things. so I would like this process to not a) slow down the app by blocking the user, b) preferably add the views in a background thread. The dilemma is that I think android doesn't like views to be added in a non-UI thread, so is there a best practice for this? I plan to have a progress bar view object visible in the fragment's view while the rest of the views are being generated with the addView and associated computations Romain Guy Instead

How to know if this thread is a UI Thread

浪尽此生 提交于 2019-12-03 02:31:09
Is there any way on Android to know, if the thread running my code, is the UI Thread or not ? In swing there was SwingUtilities.isEventDispatchThread() to tell me if i am on the UI Thread, or not. Is there any function in the Android SDK that lets me know this ? Fenix Voltres Answer borrowed from here: How to check if current thread is not main thread Looper.myLooper() == Looper.getMainLooper() Any Android app has only one UI thread, so you could somewhere in the Activity callback like onCreate() check and store its ID and later just compare that thread's ID to the stored one. mMainThreadId =

Is a good practice create anonymous AsyncTask for parallel small known freeze process? [closed]

匆匆过客 提交于 2019-12-03 00:12:13
Closed . This question is opinion-based. It is not currently accepting answers. Learn more . Want to improve this question? Update the question so it can be answered with facts and citations by editing this post . E.g.: you gonna do something that will take a few seconds and don't wanna freeze your UI thred, right? You could use an AsyncTask but you don't wanna create a external (or inner) class to solve a small freeze problem. So, is a good pratice do it? package com.example.stackoverflowsandbox; import android.os.AsyncTask; public class Foo { // E.g. before call foo method you change you

OperationQueue.main vs DispatchQueue.main

主宰稳场 提交于 2019-12-02 22:12:06
When you need to perform something on the main thread in the completion block of a networking task or an operation, which of these ways to get it would be the most appropriate and why?: OperationQueue.main.addOperation DispatchQueue.main.async MrMage For details on the differences between the two types of queue, see Lion's answer. Both approaches will work. However, NSOperation is mostly needed when more advanced scheduling (including dependencies , canceling , etc.) is required. So in this case, a simple DispatchQueue.main.async { /* do work */ } will be just fine. That would be equivalent to