3:55 AM
hey @viv
 
viv
hey cyberrog u there ??
yes i m here
 
yeah
 
viv
i was not having permission to answer in that room
 
so can you hel me with a progress dialog on a separated thread?
 
viv
looks like the window has finished or that context which used for creating dialog is no longer there.........
 
3:57 AM
im implementing a separated thread for access the calllog and update the database of my app for the first time
so, in first instalation,it does that
but it was showing and ANR error
and I tried to implement it. but its not working.
Id like a thread that call the method that access the calllog, and while it updates it shows the progressbar
can you help me?
 
viv
kkkk so i thing u might have used handler or something like that.........
 
yeah
here is the code
 
viv
kkk let me see........... hope i can find a soln
 
the error:06-15 01:00:01.113: ERROR/WindowManager(21948): Activity com.myapp.app.UpdateDBProgressDialog has leaked window com.android.internal.policy.impl.PhoneWindow$DecorView@4052a130 that was originally added here
 
viv
well try initializing handler inside onCreate()
 
4:03 AM
@viv ok
like this?
@Override
	public void onCreate(Bundle icicle) {
		super.onCreate(icicle);
		setContentView(R.layout.main);

		handler = new Handler() {
			@Override
			public void handleMessage(Message msg) {
				pd.dismiss();
			}
		};

		pd = ProgressDialog.show(this, "Updating Database",
				"The application is updating the database. Please wait.", true,
				false);
		Thread thread = new Thread(this);
		thread.start();

	}
 
viv
yes
 
im gonna test
 
viv
kkkkkk let's see
 
same error LOL
 
viv
ooooooooo ........... next attempt.............. 1 min
just comment out handler.sendEmptyMessage........... see if error comes
 
4:08 AM
yeah it comes
Kkkkkkk
 
viv
but it shouldn't come........... ????
 
aghh what am i gonna do??
 
viv
wait...........
 
@viv it shouldnt? I dont know
 
viv
wait wait
try some thing like this........... pastebin.com/eEw63QPf
 
4:14 AM
well i have to declare handler outside the method scope right??
 
viv
yeah
i just did it on text editor
so there may be some errors
 
ERROR
=(
 
viv
same one ?????
 
yeah
 
viv
are you calling this complete activity or some where u have used getDecorView() ???????
 
4:16 AM
I dont think Ive used getDecorView
you mean when I call this activity??
who starts this activity is a service
it starts like this
Intent dialogIntent = new Intent(getBaseContext(), UpdateDBProgressDialog.class);
			dialogIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
			getApplication().startActivity(dialogIntent);
 
viv
kkkkk looks correct i think i will have to run this code my self........
1 min again
 
ok
 
viv
one thing more........ where u are calling activity, try to toast ........... i think there is something wrong with context only..............
 
@viv you mean in the service??
toast a single message??
 
viv
yes
 
4:23 AM
ok, can I test it now?
 
viv
i have checked that code................ it is working fine ..........
there is some prob from service end only
try a toast
 
it prints the toast normally
 
viv
kkkkk now toast inside ur activity
it will also come properly i think
 
@viv the progressbar activity??
in the oncreate method??
 
viv
yes
 
4:26 AM
normally
it printed the toast also
 
viv
ops
 
why?
 
viv
for toast u used getBaseContext() or this.........
 
this
for the service I used this.getApplicationContext()
for the activity only this
 
viv
kkkk this is creating problem......... the dialog should come if it's showing toast.........
 
4:30 AM
what should I do?
 
viv
try to use getApplicationContext in dialog......... if it does not comes still............ post a quest on SO........... i will be also searching
 
in dialog post this.getApplicationContext() ??
 
viv
yeah
 
now the error is other
 
viv
one thing more i hope u are not killing this activity from any where.............
 
4:34 AM
ERROR/AndroidRuntime(23096): Caused by: android.view.WindowManager$BadTokenException: Unable to add window -- token null is not for an application
 
viv
see if ........ getApplicationContext() is returning null
 
im gonna Log it
 
viv
hmm
 
no its not null
it says its in this line
pd = ProgressDialog.show(this.getApplicationContext(),, ...
 
viv
uuuuhhhhh....... it's frustating.......... lol
 
4:38 AM
what am i supose to do?
 
viv
post a quest
and be here'
 
okay
look at this
26
Q: Android: ProgressDialog.show() crashes with getApplicationContext

FelixI can't seem to grasp why this is happening. This code: mProgressDialog = ProgressDialog.show(this, "", getString(R.string.loading), true); works just fine. However, this code: mProgressDialog = ProgressDialog.show(getApplicationContext(), "", getString(R.string.loading), true); throws the ...

 
viv
kkkkkk change ur alert dialog ........ a bit
as they say
 
how
 
viv
AlertDialog alertDialog = new AlertDialog.Builder(mycontext).create();
mycontext = this
 
4:44 AM
before the show?
but its not an alertdialog, its a progress dialog
 
viv
comment out ur progress dialog for some time
 
so, should I create another??
 
viv
yeah
 
ok what now
 
viv
now alertDialog.show();
 
4:47 AM
now
06-15 01:47:30.468: ERROR/WindowManager(23536): android.view.WindowLeaked: Activity has leaked window com.android.internal.policy.impl.PhoneWindow$DecorView@4052a220 that was originally added here
=(
I dont think we should use this.getApplicationContext
 
viv
try with this in ALertDialog
remove ApplicationContext and use "this"
 
use only this?
but im using only this
 
viv
kkkkkkkk sorry........
u said "I dont think we should use this.getApplicationContext"....... that's why
 
i tried using getBaseCOntext, but nothing.
 
viv
kkkk
 
4:54 AM
you have any idea??
do you think this will update my database without return an ANR error??
 
viv
nops....... i have tried every thing i knew
 
this class will avoid the ANR problem??
 
viv
yes
 
so the only problem is with this dialog right??
06-15 01:57:36.722: ERROR/AndroidRuntime(23884): Caused by: android.view.WindowManager$BadTokenException: Unable to add window -- token null is not for an application
 
viv
yes
 
4:58 AM
what am i gonna do?
i have no idea of what to do.
 
viv
have u posted quest ?
 
no. im looking for some first
 
viv
k
 
Some questions have talked about having this problem when creating a dialog from onCreate, which happens because the activity isn't created yet
dude, with this it shows the error that the view has leaked..., and with this.getApplicationContext() it shows the null problem
 
viv
i tried starting activity from service it's working fine...............
should i upload my files
 
5:06 AM
yeah
 
viv
??
 
of course
 
viv
kk 1 min
 
where are you going to upload it?
 
viv
git hub....... just 2 files
 
5:11 AM
ok
you can pastebin it
 
gonna test
 
viv
k
when u start the activity after the dialog dismisses u finish it by back key....... because it will again be started by service after some delay
 
what is the back key
how do I create an object of a service
so I can access the methods of the service
 
viv
just paste those two files........ u have to do nothing that service will be started from activity
 
5:18 AM
I just want to call the method from the service
this progressbar is not suposed to start a service
this is started in a broadcast receiver
 
viv
kkkkkk so start the activity from ur broadcast receiver
 
in the service, I check if my db is empty, if it is, I have to call the progressbar
is the service that have to do that
 
viv
not understood
?
 
in my service onCreate(), I check if my db is empty. if it is, I call the method that updates my db
got it??
 
viv
eys
yes
 
5:20 AM
but, this way was returning an ANR error. So I had to create this thread with progress bar
 
viv
kkk
 
so, instead of calling the method directly from the service, I call the progressbar, and this one calls the method that updates
got it?
hey it showed the progressbar. I just dont know if it is calling the method
 
viv
u call the activity.......... it shows progress bar, starts thread, u perform operations in thread, and then thread dismisses dialog,......... i understood this........
 
yes
its showing the thread
but its lating too much to dismiss
 
viv
k
 
5:22 AM
its getting all data from calllog and inserting in DB
 
viv
problem ?
 
its not entering my method. Ive putted a log, but it didnt printed
look
@Override
	public void onCreate(Bundle icicle) {
		super.onCreate(icicle);
		setContentView(R.layout.main);
		pd = ProgressDialog.show(this, "Updating Database", "The application is updating the database. Please wait.", true, false);


		handler = new Handler() {
			@Override
			public void handleMessage(Message msg) {
				pd.dismiss();
			}
		};


		Thread thread = new Thread(){

			public void run() {

				try{

					rcs.updateDB(); //I WANT TO ENTER HERE
					handler.sendEmptyMessage(0);

				}catch(Exception e){e.printStackTrace();}
see? Ive commented with "I WANT TO ENTER HERE
"
is there the right place to put it??
 
viv
it should come to rcs.updateDB(); .......
 
yeah
rcs is my service object. is it right??
 
viv
yes it is right
i hope u will be able to do it from here
 
5:28 AM
@viv ok
thanks
 
viv
my pleasure