In my application i need to decrypt the certain message format, to extract information like message id, timeout and so on.i need to show an corresponding image for the given id as well as to show it for the mentioned time period.
For that i have created one custom layout to show the image and other details. i'm using imageview for displaying the image. but dont know how to set timeiut for that?
Do anyone have idea on that?
You can easily use Handler to do that, like this
imageuser.setImageBitmap(bitmapObject);
new Handler().postDelayed(new Runnable() {
#Override
public void run() {
imageuser.setImageBitmap(null);
}
}, 5000);
here, imageuser is your ImageView and replace 5000 with your specific time in miliseconds.
Just use it like whenever you want to show image just call your UI and start a thread for the given time you want to show the image and when the time complete just make that ui visibility gone,this is the logic try it in your own way.
thanks
Related
I have an ImageButton (btnOpen), and I want to change its background, but just for a second, for example.
I know the method to do this (I use btnOpen.setBackgroundResource(my_resource); ), but how can I do that without making my UI non-responsive?
What's the best and simplest way, do I have to use something like Handler or runOnUIThread?
Thanks for help.
One way to deal with this is to preload your ressource programmatically using a Handler.
I think this post can help you https://stackoverflow.com/a/12523109/665823
But usually if the UI is getting block by loading a single image ressource this means your ressource is too big. Try checking this out first.
Use a handler
new android.os.Handler().postDelayed(new Runnable() {
#Override
public void run() {
imageView.setBackgroundResource(R.drawable.something);
}
}, 1000);
I need to be able to cancel tasks involving web requests.
but I got some issues of memory management and exception handling when something fail.
For example:
I want to create a text edit for searching apps in user device.
so whenever user end a key, I want to clear current search task, and restart search.
The problem I got is in android 4.4, when trying to load the label of the app (to get it's name) I get an exception.
Also of I try to search contacts I'm getting an invlalid uri, fo rcontact photo.
I don't want any help dealing with this errors, I want a solution that will help me ignore this erros (try catach dont work) currently the entire ui get's stuck and app crash.
I'm using the executors service and call cancel when user gives me an input. but it's not enough.
Any advice will be appreciated, thanks.
if you're using AsyncTask i would like to suggest you to make it like this
AsyncTask<Void, Void, Void> a = new AsyncTask<Void, Void, Void>(){
#Override
protected Void doInBackground(Void... params) {
return null;
}
};
a.execute();
// at some point you want to cancel just use
a.cancel(true);
You can even put tasks together in List or array and loop to cancel it whenever you want.
You can try like this: what you want is getting result in background by network and show result in view ,you can Register a Listener to one task,. you can callback method of listener to use show result in view if it get the results in background ,if you do not need the result of current task and want satrt the next task ,you can only remove listener of current task,so the view will not reload
This is my idea ,I am so sorry for my bad english , if you do not see ,you can send message to me, and my email is bjltxsp#gmail.com
I want my application can get user's input of time (HH:mm) from EditText widget.
Based on this time value my app needs to show a dialog when current time matches entered time.
Gaauwe
*Edit*
I want to place an EditText widget in my app.
A user will fill it with some time value (e.g. 10:30).
Then when real time (10:30) come up a dialog will be shown.
I think you can use the AlarmManager for this.
I d suggest you have a look at some tutorials like these to help you get started
http://michael.theirwinfamily.net/articles/android/android-creating-alarm-alarmmanager
http://android.arnodenhond.com/tutorials/alarm-notification
That is not too difficult. When user finished editing you EditText, read the time value and create instance of AlarmManager with start time calculated as difference between current time and whatever user wrote in the EditText. Better to use TimePicker to avoid parsing user`s input. Add receiver for you AlarmManager, receiver will start Service which will show dialog or do anything you want. You need to use AlarmManager because if your device is sleeping nothing will wake it up except system call like AlarmManager. #Zortkun 's post with links will help you to figure out how manage AlarmManager.
try this :
use the service : then when user enter time starts a service when system time and user entered time match the shows..
You can pull the data out of the EditText with:
findViewById(R.id.yourEditText).getText().toString();
The rest of your question I didn't understand.
RAW WAY!
So when user put text inside edittext and click button, you could save text in this way:
String time = findViewById(R.id.yourEditText).getText().toString();
and start a thread that check for time, and when time is equal to user's string time, you can show a dialog :)
Thread t = new Thread(new Runnable(){
public void run(){
while(new Date().getLocalTime()!=usersTime){ // is just pseudocode
Dialog.show();
}
}
});
I'll try to understand...
Seeing as you know how to pull the text from an EditText, you'll need an if statement.
Something that compares that time to the current time.
if (editTime == realTime) {
Toast.makeText(getApplicationContext(), "RING RING RING",
Toast.LENGTH_SHORT).show();
}
Use something like this:
Read this to figure out how to get a string of current time.
Hi i want to display the imageviews one by one that means if image1 is displayed after 2 sec another image is displayed .but i don't want to use threads why because my application is small.I want to use handlers.So give me some suggestions,Thanks in advance
You can do one thing for displaying images in imageview at 2 sec's interval: Implement Timer Control.
And write image setting code on onTick method of CountDownTimer class.
public void onTick(long millisUntilFinished) {
imgView1.setImageResource(imgValue);
}
You can refer This example and implement something like that.
Enjoy!!
I am suing Listview and customize listview to display image inside a list item.
I want display image with every search result.
to display complext listeim i am following the following example
http://developer.android.com/guide/samples/ApiDemos/src/com/example/android/apis/view/List4.html
inside wrapper class i am initiating new thread for every new list item's image so that i won't dealy the displaying image.
my code is below
new Handler().post(new Runnable(){
#Override
public void run() {
Drawable dImage = Util.getImageFromURL(imageURL);
getImageIcon().setImageDrawable(dImage);
}
});
mean 10 images initiates 10 different image loading threads other static data is not inside thread.
problem arises when during image loading page application getting hang it should not hang.... any idea what to do ?
alt text http://img509.imageshack.us/img509/7519/thumbnailx.jpg
Use a background operation to retrieve your images, such as an AsyncTask. All your new Handler().post() stuff does is delay the work by a nanosecond, not have it be performed in the background.
Also, if you are going to use Handlers, just create one.