android


Android: one handler for all runnables?


Can I use one handler in my Activity for all runnables or should I have multiple instances of Handler, each for one runnable?
You can use only one handler and to specify from where your are coming use different message.
handler.sendEmptyMessage(messagevalue); //use this to send message from different place
Now handle message
private Handler handler=new Handler(){
#Override
public void handleMessage(Message msg) {
super.handleMessage(msg);
//specify msg value
if(msg.what==10){
//do this
}else if(msg.what==20){
// do this
}else{
//so on....
}
}
};
I would say, that you should have one handler per thread (not per runnable), unless you do not need completely different behavior for different kinds of runnables.

Related Links

Drawing Image on Android
TextView real height with wrap_content single line
Firebase onDataChange method is not called even if the data is changed
Android AsyncTask + Handler, no data updated to Main Activity UI
Android - How to use XML feed from webpage?
android databinding: how to avoid onCheckedChanged triggered by programmatically
Android Support Library v7 PreferenceFragment Preference Headers
getAdapterPosition() is not found as a method
Android Simulator Date/Time is set to previous day
Why my APK is working just in Samsung phone?
Seekbar Controlling Soundpool, stops working
Android Signed APK showing as Unsigned APK when trying to upload to production
How to cancel a realm transaction in process
Permission denied cordova-plugin-file-opener2
Error launching react project on Android Studio emualator
BluetoothSocket connect always fails

Categories

HOME
paraview
checkstyle
ns-3
solaris
rendering
simulink
opengl-3
recordrtc
elasticsearch-5
categorical-data
enthought
code-generation
renjin
docx
bitnami
parameter-passing
standards
fileserver
asp.net-mvc-viewmodel
xmonad
soci
shortest-path
delphi-xe5
lilypond
asciidoctor-pdf
question2answer
r-mice
dapper-extensions
mat
nstimer
failover
testcomplete
weather
deltaspike
quickfixj
hard-drive
instantiation
mnist
apriori
angular-http
phpdbg
dtsearch
static-cast
rackspace-cloud
cmp
baidu
javafx-css
custom-lists
flex-monkey
tinkerpop3
mapinfo
xdoclet
embedding
httpruntime.cache
atan2
intel-c++
binomial-theorem
text-search
mod-proxy
linked-tables
nsurlsessiondatatask
snackbar
matlab-deployment
uvc
fits
variadic-templates
iso-prolog
kissfft
codeplex
xmltodict
code-duplication
cocoalibspotify-2.0
android-icons
swfobject
fb.ui
android-sdk-2.3
resource-management
curb
rmiregistry
boost-signals
gobject-introspection
fsevents
filemerge
photolibrary
easyb
hbm2java
tabpanel
murmurhash
spread

Resources

Database Users
RDBMS discuss
Database Dev&Adm
javascript
java
csharp
php
android
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App