Android :: Android - Why UI Still Blocks When Worker Thread Used?
Oct 17, 2010
package com.commonsware.android.threads;
import android.app.Activity;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ProgressBar;
import android.widget.TextView;
import android.widget.Toast;
public class HandlerDemo extends Activity {
Thread mBackground; ProgressBar bar;
Handler handler = new Handler() {
@Override
public void handleMessage(Message msg) {
bar.incrementProgressBy(5);
} }; boolean isRunning = false;
@Override
public void onCreate(Bundle icicle) { super.onCreate(icicle);
setContentView(R.layout.main); bar = (ProgressBar) findViewById(R.id.progress);
} public void onStart() { super.onStart(); bar.setProgress(0);
mBackground = new Thread(new Runnable() { public void run() { try { int a = 0;
for (int i = 0; i < 20 && isRunning; i++) { for (int j = 0; j < 2000; j++) {
for (int k = 0; k < 1000; k++) { a++;
} } handler.sendMessage(handler.obtainMessage());
} } catch (Throwable t) { // just end the background thread } } } );
findViewById(R.id.LoginButton).setOnClickListener(
new OnClickListener() { public void onClick(View v) { mBackground.run();
} } );
isRunning = true;
} public void onStop() { super.onStop();
isRunning = false;
} }
View 1 Replies
Aug 28, 2009
I am seeing some weird issues and looking to see if anyone knows what is going on. I have a BroadcastReceiver which updates some views on receiving an event. Some psudo code is shown below. What happens is the function runs fine and the app seems to update the textviews BUT when i then try to clear the textviews parent and add new textviews the linearlayout(parent) blanks out and will now draw any of it's children.
View 2 Replies
View Related
Aug 8, 2010
I was trying to post a toast notification in case something goes wrong in a worker thread. I do this by putting a handler.post(funcFailed) in the catch block where funcFailed it a runnable and simply called a function funcFailedshow()
funcFailedshow() is defined to be Toast.makeText(App.this,"Error in funcfailed", Toast.LENGTH_LONG).show();
For some reason i cannot see the toast notification. Even if i replace App.this (app is the applications name) with a getApplicationContext() it does not work.
View 2 Replies
View Related
Jul 20, 2009
My app forwards MotionEvents, reported by GestureDetector.OnGestureListener, to a worker thread. Right now i am doing it by calling MotionEvent.obtain, pass the obtained copy to the worker thread, handle it and recycle it at the worker thread. Is it required to obtain and recycle a MotionEvent if it is passed to another thread? Or could it safely be skiped? If i am making things overly complicated, could you please explain me at which conditions MotionEvent.obtain is usually called?
View 2 Replies
View Related
May 26, 2009
I'm implementing a service that contains a thread to handle all time consuming operation. My core service logic is in a different thread than the ui or main thread. According to the Android document, when the OS plans to free some system resource, it will call onDestroy () on the service and only when onDestroy() returns it will kill the process hosting the service, thus giving opportunity to the service to cleanup.Now, when onDestroy() is called, I want to send a message to my service thread to do the necessary cleanup. Only when the service thread acknowledges that the cleanup or shutdown is complete, onDestroy () should return. I could find a way to send asynchronous messages to threads and the corresponding processing of the messages, but not able to figure out how I need to implement onDestroy(), such that it would send a message to the service thread and should wait for a result, before returning.
View 13 Replies
View Related
Jun 29, 2010
Droid Blocks is a classic sliding block puzzle with a sci-fi twist and over 500 levels.
You can get it from the marketplace (lite version also available) or from Droid Blocks Official Website for only 1.99$.
View 3 Replies
View Related
Jun 24, 2009
I have a service running in the background.I have a background thread that gets a reference to the service from the application's main activity. But when the background thread calls a method in the service to display a toast, I get the "Looper not initialized exception".Why,if I have a valid, bound reference to a Service, does this still happen?
View 4 Replies
View Related
Sep 7, 2010
How can I implement a run() method of thread if I create a Thread Global?
I mean If I create a Thread Globally then can I implement its run() method {" public void run()"} anywhere in my Application?
In the run() method I have to write the code to perform some action.
IF I can do it then please can anyone show me briefly how to do it particularly.
View 2 Replies
View Related
May 21, 2009
I am writing an application in which i need to handle messages between the main thread(the deafult UI related thread) and the user created Gamethread.
The requirement is like this.
An activity(say "Activity_X") is setting the view by "setContentView(some "View_Y")". In "Activity_X" i have implemeted "onCreateOptionsMenu()" and "onOptionsItemSelected()" fucntions for creating menus & a switch case for action to be taken on selecting those menus.Menu has items like "resume/pause/zoom/" .
All action to be take on selecting these menus are implemented in "View_Y" in a separate Gamethread by extending "Thread" class.
So whenever a menu is selected in "Activity_X" i need to send a message to "View_Y". And on receiving this ,a particular action/method should be called in View_Y(GameThread).
How can i achieve this using Handlers?Is there any other way of doing this? Please do share with me some code snippets for these.
View 3 Replies
View Related
May 27, 2010
I have a separate thread running to get data from the internet. After that, I would like to update the ListView in the main thread by calling adapter.notifyDataSetChanged(). But it does not work. Any workaround for that?
View 1 Replies
View Related
Jul 22, 2009
I want to do the drawing in another thread to speed up the game(it is way to slow right now). I was told to do this but don't quite understand why that would speed things up. Is it GameView that should implement Runnable? Should I make the thread sleep when not drawing? where should I start the thread? package com.android.WWS;
import android.app.Activity; import android.content.Context; import android.graphics.*; import android.os.Bundle; import android.view.SurfaceView; import android.view.KeyEvent; import android.view.View; import android.view.View.OnKeyListener; import java.lang.Runnable; import java.lang.Thread;...................
View 4 Replies
View Related
Nov 13, 2010
I'm making an application which will utilize both touchevents and sensorevents. The problem with touchevents is that they fire off very often, and thereby consumes massive amounts of CPU time. The common solution is to do a Thread.sleep to make it cool down.However, if one wants to use both the onTouchEvent and onSensorChanged in the same activity, applying the Thread.sleep hack will also slow down onSensorChanged. This is obviously caused by the two methods being called from the same (ui) thread.Is there some way to call onTouchEvent from a different thread than the ui, so one could do the Thread.sleep trick without slowing down onSensorChanged as well?
View 1 Replies
View Related
May 23, 2010
I'll be new to Android starting on June 4th and I'll be retiring my Blackberry Tour. There are a few apps on my Blackberry that I really like and use daily. So I have a few questions for the Android gurus out there.
1. Exchange Email- I work for a Computer Company that blocks access to their Exchange Server and although I've requested access repeatedly, they deny me every time. Is there a work around for Android similar to the Blackberry Desktop Redirector?
2. Sirius/XM- I know it's not available yet for Android but I was wondering if anyone has an update on the future availability of this App for the Evo.
3. Password Keeper- I would not be able to survive without this App on my Blackberry. Is there something as good or better available on the Android Market?
4. Can anyone recommend a good Chess Application for the Evo?
View 4 Replies
View Related
Dec 28, 2009
I have a thread that constantly polls a UDP connection and posts the received data to another thread. It uses a connected DatagramSocket, reads a packet (which is always the same side), gets the data and posts it to a message queue (not the android one, my implementation). The problem happens mainly over 3G connection, not wifi.
Code looks like:
CODE:...............
View 2 Replies
View Related
Jun 17, 2010
I have an HTC Incredible and I noticed what appears to be protected blocks on one of the home screens. The home screen has only a couple of programs on it that take up 1 block. When I tried to move the location of one of the programs, I noticed there is a 1x2 vertical strip that is blank that is just to the top right of center that won't allow me to place anything. There is no reason why I shouldn't since there is plenty of room on the screen. Could there possibly be something hidden there? All i see is the background and touching that region does nothing.
View 1 Replies
View Related
Nov 5, 2009
I'm trying to put a checkbox into ExpandableListView. I noticed that doing that disables basic functionality of displaying child list when group row is clicked. Furthermore when I click outside of checkbox the click is detected by nether checkbox nor by OnGroupClickListener. Can someone help me to resolve this? The CheckBox works fine though including detecting clicks when clicking directly on the box.
View 2 Replies
View Related
Oct 10, 2009
I am starting a service from an activity. Once the services starts, the calling activity loses focus and blocks till the service is completed. Why is this and is there a way around it to return the control to the calling activity while the service runs in the background?
View 6 Replies
View Related
Aug 18, 2010
why is it that youtube blocks so many videos from being viewed on mobile? does not compute. is this at google's discretion, or carriers?
View 4 Replies
View Related
Feb 19, 2010
I assume that when I do a read on the inputstream, it blocks until it gets more data to read.
I also assume that when the connection is closed, the read throws an IOException.
The problem is that sometimes when I change the connection from carrier to WiFi or from WiFi to carrier, the read just gets stuck and never throws the IOException.
The SDK is 1.5 and the phone a HTC Hero.
This behavior is quite ugly for me because I need to stay always connected.
Does someone else have ever seen this problem ? Is it a bug or am I the bug?
View 2 Replies
View Related
Aug 29, 2010
How can you scroll down in the Blocks Editor window?It lets me scroll down a little, but not to the end of my (lengthy) code.
View 1 Replies
View Related
Feb 20, 2009
I need to suspend/resume a thread from another thread in the same process. I tried to look into thread apis,but I couldn't figured out a way to achieve this.Can anyone pls point me some references to look or give a tip to do this.
View 2 Replies
View Related
Jul 16, 2010
The Android doc says "Like activities and the other components, services run in the main thread of the application process." Is the main thread here the same thing as UI thread?
View 3 Replies
View Related
Nov 4, 2010
Blocks is an original logic game. Your aim is collecting all rubies. It's very hard, but you should try it!
trial version
Blocks trial ~ Android Game v1.0 By rewqgame | Brain & Puzzle
full version
Blocks ~ Android Game v1.0 By rewqgame | Brain & Puzzle
View 5 Replies
View Related
Dec 28, 2009
Does anyone know how to delete certain texts from a thread in an easy manner instead of having to delete a whole thread??
View 7 Replies
View Related
Jul 12, 2010
Skype Blocks Fring ? Or Not? Fingerpointing... But Where is Skype for Android? So what will we use now for video calling on our Evo's ?
View 3 Replies
View Related
May 23, 2014
Is there an app that really blocks SMS text from blacklisted numbers? Avast is working on their software, since Google broke text blocking with KitKat. But any already released software that really works with KitKat? (I used the Nexus 5 SMS app on my Nexus 7 in order to restore SMS, but along with good text is a lot of spam. Go SMS Pro does not work for me, it will only save drafts, not send or block.)
View 3 Replies
View Related
Jul 30, 2009
Hero On Orange not letting me sign in to google account
But normally everything should work on my simcard....
Now the other part...Im from Belgium. The htc hero is not launched yet in Belgium because they need to remove the youtube app.
So I went to netherland and bought a htc hero! Hehe...but then I tried to connect to the market...so I tried to connect to my gmail account and I got the same error as the guy above...From the simcard/service etc...
Now I called my provider..he sais my simcard is quite new...so normally their shouldn't be any problem. I don't got data activated yet...but I'm connected true wifi...so that shouldn't be the problem? To be sure I activated the service right now..and waiting to get activated...
Could It be that my htc is blocked because I'm using one from the netherlands in Belgium?because of the situation with the belgium htc's?
View 3 Replies
View Related
Jun 8, 2010
The Wi-Fi network at my workplace apparently blocks mobile devices somehow.I can connect to the network fine but cannot load any webpages or connect through any apps on my Desire. It works fine however on my laptop.Has anyone else encountered this and more importantly is there a way round it?
View 30 Replies
View Related
Aug 3, 2010
Just noticed that now that with the 2.2 update we can now go to espnradio.com and stream with our browser. Kinda defeats the purpose of buying the espnradio app (like I did last month).
View 12 Replies
View Related
Jul 16, 2012
Basically I am looking for an app that will allow me to sort my contacts in groups and will block certain groups to call me for example during the night but other group of people will be allowed to contact me during the night, weekends, etc.
Nokia has this option as default but I am not aware of this feature on my Desire S.
View 1 Replies
View Related