ui-thread

Android UI: when can I directly modify a view?

百般思念 提交于 2019-12-23 07:28:08
问题 I have an app with two activities. From the main activity I start a secondary activity using startActivityForResult() . The secondary activity returns data (in the form of an Intent object) to the main activity. On the main activity I have a method onActivityResult() to handle the come back from the secondary activity. Within this onActivityResult() method, I need to update a View on the main activity (to reflect the new data values). I do not explicitly spawn any threads. My question is: can

Understanding the UI thread

拜拜、爱过 提交于 2019-12-22 06:45:05
问题 I am a beginner to Android and I have some confusions regarding Android UI Thread . Now, I know that no thread apart from the one that created the UI can modify it. Great. Here is the Activity from my first Android app which slightly confuses me. public class NasaDailyImage extends Activity{ public ProgressDialog modalDialog = null; //------------------------------------------------------------------------------ @Override protected void onCreate(Bundle savedInstanceState){ //Instantiate

SQLite query run on UI thread with ExpandableListView/SimpleCursorTreeAdapter

江枫思渺然 提交于 2019-12-21 19:58:12
问题 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

Avoiding the window (WPF) to freeze while using TPL

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-21 06:19:13
问题 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:

Avoiding the window (WPF) to freeze while using TPL

泄露秘密 提交于 2019-12-21 06:18:27
问题 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:

Why can only the UI thread in Android update the UI?

一曲冷凌霜 提交于 2019-12-21 05:04:00
问题 Could someone please explain to me why only the UI thread in Android can update the UI? Why can't any other thread update the UI? 回答1: Documentation states that Android UI toolkit is not thread-safe. Thus, single thread model ensures UI is not modified by different threads at the same time. 回答2: As stated on the android developper guide about Thread : When your app performs intensive work in response to user interaction, this single thread model can yield poor performance unless you implement

C#/WPF - I can't update UI from a backgroundworker

爱⌒轻易说出口 提交于 2019-12-19 10:12:20
问题 I have a code that fetches tweets from a specific Twitter account using Tweetsharp library, creates instance of a custom UserControl and post tweet text to that UserControl then add it to a StackPanel . However, I have to get a lot of tweets and it seems that the application would freeze while adding user controls to the StackPanel . I tried using BackgroundWorker , but I wasn't lucky until now. My code : private readonly BackgroundWorker worker = new BackgroundWorker(); // This ( UserControl

Javafx Updating UI from a Thread without direct calling Platform.runLater

﹥>﹥吖頭↗ 提交于 2019-12-19 08:33:28
问题 Nowadays some says it is not suitable to use Platform.runLater() for updating the UI from a non-JavaFX Thread and Oracle site introduce a way with bindings for progress bar updating. Here I want to update a Label, so coded it like this: Task task = new Task() { @Override protected Object call() throws Exception { int i = 0; while (true) { this.updateMessage("Count " + i); System.out.println(i); // Thread.sleep(10); i++; } } }; Thread t = new Thread(task); lbStatus.textProperty().bind(task

Javafx Updating UI from a Thread without direct calling Platform.runLater

不羁岁月 提交于 2019-12-19 08:33:14
问题 Nowadays some says it is not suitable to use Platform.runLater() for updating the UI from a non-JavaFX Thread and Oracle site introduce a way with bindings for progress bar updating. Here I want to update a Label, so coded it like this: Task task = new Task() { @Override protected Object call() throws Exception { int i = 0; while (true) { this.updateMessage("Count " + i); System.out.println(i); // Thread.sleep(10); i++; } } }; Thread t = new Thread(task); lbStatus.textProperty().bind(task

Is SQL or general file access appropriate in the Android main UI thread?

别来无恙 提交于 2019-12-19 07:01:09
问题 I'm trying to follow Android best practices, so in debug mode I turn all the following on: StrictMode.setThreadPolicy(new StrictMode.ThreadPolicy.Builder().detectAll().penaltyLog().build()); //detect and log all thread violations StrictMode.setVmPolicy(new StrictMode.VmPolicy.Builder().detectAll().penaltyLog().build()); //detect and log all virtual machine violations Android now yells at me when I try to use any sort of file access or SQL in the main (UI) thread. But I see so many