I have an IntentService that is parsing some xlm file to create a html file. I am already done with creating that html file with some templates. But the problem is I need to change that html file for every single “media” node that I parsed from my file. And then according that new incoming type I have to create a new corresponding html file to view via a WebView.
So far I tried to create some handlers and pass intent to WebView class. ( I am not sending any data via bundles. I just create that html file in my service class then call that file from WebView.) This think works for the first time. However after first media is over I couldnt call the same activity for the 2nd time.
Code piece for calling WebView is the following:
if(counter == 0){
createDir(); //function to create html file with corresponding date
Intent sender = new Intent(getApplicationContext(), webLoader.class);
//System.out.println("here");
sender.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(sender);
}
else
{
//System.out.println("entering?");
System.out.println(durationOfMedi);
new Handler().postDelayed(new Runnable() {
public void run() {
// TODO Auto-generated method stub
try {
createDir(); //function to create html file with corresponding date
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
Intent sender = new Intent(getApplicationContext(), webLoader.class);
sender.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(sender);
}
}, durationOfMedi*1000);
}
What I am basically trying to do is, I iterate through each media item and according to their values and etc.. I make another html file within the IntentService and then I try to start my WebView activity in order to view that html file. Each of those media items have some duration to be seen in the screen so that is why I used postDelayed after the first media and I keep its track with some variable “counter”.(With first media I directly create file and show it but after that I wait for some time “durationOfMedi * 1000” miliseconds.) But it didnt work after first media. It just loads that item to screen via html file and then it wont enter new Handler()… method.
If anyone can help me I would appreciate it. I am clueless about it atm.
I accomplish that situation by directly sleeping the current thread for some certain amount of time which is done like this:
by applying that kinda method i can fire other activity. And in order to avoid too many task on stack, I also include:
in my manifest file. That did the job. I am posting this if anyone comes into such a situation.