[android-developers] Singletons in Android .... Final solution?

2012-05-03 Thread DebUggEr
I have been testing and experimenting with android low end devices and 
trying to find a consistent solution for singletons in android. I beleive I 
have gone through most posts addressing this issue and I am pretty sure 
that I have a good solution.

http://www.devahead.com/blog/2011/06/extending-the-android-application-class-and-dealing-with-singleton/
 

 I found that *sometimes some static variables bound to activities 
happened to be uninitialized even though they’ve previously been 
initialized!* I thought that when a static variable is initialized it stays 
so for the entire life of the application, but this doesn’t seem to be the 
case. Among all the information I found on the web, I tried to find out a *safe 
and reliable way to initialize static variables* (and you know that the 
singleton design pattern requires the use of a static variable). The 
explanation of the weird behavior I saw that makes more sense to me is that 
*the static variables instances are bound to the class loader of the class 
that first initialized them*. So what does this mean? This means that if a 
static variable inside any class has been initialized by an activity, when 
that activity is destroyed also its class might be unloaded and so the 
variable becomes uninitialized again! While if the variable is initialized 
by the application class, it’s life is the same as the application process 
so we’re sure that it will never become uninitialized again. That’s why I 
chose to initialize all the singletons in the *MyApplication* class.

I want experts to look into this and confirm that this dosent has any 
serious drawbacks. I am opposing this solution as previously discussed in 
this same group 
https://groups.google.com/forum/?fromgroups#!topic/android-developers/2i82mjoM46M/overview


Anxious.

-- 
You received this message because you are subscribed to the Google
Groups Android Developers group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Re: [android-developers] Singletons in Android .... Final solution?

2012-05-03 Thread DebUggEr
I think I got my bit to research further more into it! But just look at 
this one final argument.

I am not telling the solution in my above mentioned post is correct. But 
the only solution that ensured that my static data was consistent was to 
convert it from static data to an object of Application class. (The 
solution that is mentioned in the blog post). Consider this scenario

1) Activity A(SingleTask) launches Activity B
2) Activity B uses static Data containing boolean, int and arraylist.
3) send it to background, and return after 45 mins. Returned to Activity A 
. 
4) Check static Data. int initialized to garbage. Boolean to false. 
arraylist to null.

No, the application wasn't killed or restarted, my logs also show the 
PID(dosen't change). I am performing absolutely nothing when the app is in 
background so I am giving android no reason to clear memory or close 
activity.

Convert static data to a object of application class and no logical change 
at all(I did a Tit for Tat). This issue is fixed. 

If you think this bit I mentioned is impossible just direct me to 
a resource/book that makes me design more definite tests to prove this or 
gives me an insight to static data handling inside the DVM, JVM etc. It 
cant be possible Mobile OS that has cases of sleep, hibernate, lock and low 
memory conditions will just make sure that static data stays there. Even if 
the application is marked as always running.

Appreciate your time.

On Thursday, 3 May 2012 16:02:37 UTC+5, Mark Murphy (a Commons Guy) wrote:

 AFAIK, the quoted passage is mostly incorrect. Classes are not 
 unloaded once loaded. 

 There can be issues with static data members if you use multiple 
 ClassLoaders -- AFAIK, you get the same effect in traditional Java. 
 However, you should only encounter that when you create your own 
 ClassLoader for one reason or another. And, of course, when the 
 process goes away, static data members go away, but so do custom 
 Application subclasses. 

 If you examine the Android frameworks' source code, it is littered 
 with static data members. Furthermore, based on a quick survey, only 
 about half of the AOSP apps have a custom Application subclass, and 
 half of those simply use it to initialize static data members. 

 On Thu, May 3, 2012 at 2:01 AM, DebUggEr sjkliteral.w...@gmail.com 
 wrote: 
  I have been testing and experimenting with android low end devices and 
  trying to find a consistent solution for singletons in android. I 
 beleive I 
  have gone through most posts addressing this issue and I am pretty sure 
 that 
  I have a good solution. 
  
  
 http://www.devahead.com/blog/2011/06/extending-the-android-application-class-and-dealing-with-singleton/
  
  
   I found that sometimes some static variables bound to activities 
 happened 
  to be uninitialized even though they’ve previously been initialized! I 
  thought that when a static variable is initialized it stays so for the 
  entire life of the application, but this doesn’t seem to be the case. 
 Among 
  all the information I found on the web, I tried to find out a safe and 
  reliable way to initialize static variables (and you know that the 
 singleton 
  design pattern requires the use of a static variable). The explanation 
 of 
  the weird behavior I saw that makes more sense to me is that the static 
  variables instances are bound to the class loader of the class that 
 first 
  initialized them. So what does this mean? This means that if a static 
  variable inside any class has been initialized by an activity, when that 
  activity is destroyed also its class might be unloaded and so the 
 variable 
  becomes uninitialized again! While if the variable is initialized by the 
  application class, it’s life is the same as the application process so 
 we’re 
  sure that it will never become uninitialized again. That’s why I chose 
 to 
  initialize all the singletons in the MyApplication class. 
  
  I want experts to look into this and confirm that this dosent has any 
  serious drawbacks. I am opposing this solution as previously discussed 
 in 
  this same group 
  
 https://groups.google.com/forum/?fromgroups#!topic/android-developers/2i82mjoM46M/overview;
  

  
  Anxious. 
  
  -- 
  You received this message because you are subscribed to the Google 
  Groups Android Developers group. 
  To post to this group, send email to android-developers@googlegroups.com 
  To unsubscribe from this group, send email to 
  android-developers+unsubscr...@googlegroups.com 
  For more options, visit this group at 
  http://groups.google.com/group/android-developers?hl=en 



 -- 
 Mark Murphy (a Commons Guy) 
 http://commonsware.com | http://github.com/commonsguy 
 http://commonsware.com/blog | http://twitter.com/commonsguy 

 Android Training...At Your Office: http://commonsware.com/training 


-- 
You received this message because you are subscribed to the Google
Groups Android Developers group.
To post to this group, send

[android-developers] Re: Singletons in Android .... Final solution?

2012-05-03 Thread DebUggEr
I will get back with a test that can prove this, as soon as I lose Codejam 
:)

Thanks for all your time.

On Thursday, 3 May 2012 11:01:37 UTC+5, DebUggEr wrote:

 I have been testing and experimenting with android low end devices and 
 trying to find a consistent solution for singletons in android. I beleive I 
 have gone through most posts addressing this issue and I am pretty sure 
 that I have a good solution.


 http://www.devahead.com/blog/2011/06/extending-the-android-application-class-and-dealing-with-singleton/
  

  I found that *sometimes some static variables bound to activities 
 happened to be uninitialized even though they’ve previously been 
 initialized!* I thought that when a static variable is initialized it 
 stays so for the entire life of the application, but this doesn’t seem to 
 be the case. Among all the information I found on the web, I tried to find 
 out a *safe and reliable way to initialize static variables* (and you 
 know that the singleton design pattern requires the use of a static 
 variable). The explanation of the weird behavior I saw that makes more 
 sense to me is that *the static variables instances are bound to the 
 class loader of the class that first initialized them*. So what does this 
 mean? This means that if a static variable inside any class has been 
 initialized by an activity, when that activity is destroyed also its class 
 might be unloaded and so the variable becomes uninitialized again! While if 
 the variable is initialized by the application class, it’s life is the same 
 as the application process so we’re sure that it will never become 
 uninitialized again. That’s why I chose to initialize all the singletons in 
 the *MyApplication* class.

 I want experts to look into this and confirm that this dosent has any 
 serious drawbacks. I am opposing this solution as previously discussed in 
 this same group 
 https://groups.google.com/forum/?fromgroups#!topic/android-developers/2i82mjoM46M/overview
 

 Anxious.


On Thursday, 3 May 2012 11:01:37 UTC+5, DebUggEr wrote:

 I have been testing and experimenting with android low end devices and 
 trying to find a consistent solution for singletons in android. I beleive I 
 have gone through most posts addressing this issue and I am pretty sure 
 that I have a good solution.


 http://www.devahead.com/blog/2011/06/extending-the-android-application-class-and-dealing-with-singleton/
  

  I found that *sometimes some static variables bound to activities 
 happened to be uninitialized even though they’ve previously been 
 initialized!* I thought that when a static variable is initialized it 
 stays so for the entire life of the application, but this doesn’t seem to 
 be the case. Among all the information I found on the web, I tried to find 
 out a *safe and reliable way to initialize static variables* (and you 
 know that the singleton design pattern requires the use of a static 
 variable). The explanation of the weird behavior I saw that makes more 
 sense to me is that *the static variables instances are bound to the 
 class loader of the class that first initialized them*. So what does this 
 mean? This means that if a static variable inside any class has been 
 initialized by an activity, when that activity is destroyed also its class 
 might be unloaded and so the variable becomes uninitialized again! While if 
 the variable is initialized by the application class, it’s life is the same 
 as the application process so we’re sure that it will never become 
 uninitialized again. That’s why I chose to initialize all the singletons in 
 the *MyApplication* class.

 I want experts to look into this and confirm that this dosent has any 
 serious drawbacks. I am opposing this solution as previously discussed in 
 this same group 
 https://groups.google.com/forum/?fromgroups#!topic/android-developers/2i82mjoM46M/overview
 

 Anxious.


-- 
You received this message because you are subscribed to the Google
Groups Android Developers group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Re: [android-developers] Re: PDF Reader in Android OS

2011-05-21 Thread DebUggEr
Khanh,

Please search code.google.com for droid reader. It is full implementation 
for you. Of course if you are a beginner you will need someone to guide you 
how to understand it.

Also, try to put more understanding to your questions. 

Sincerely,
Jehandad

-- 
You received this message because you are subscribed to the Google
Groups Android Developers group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Re: [android-developers] Re: PDF Reader in Android OS

2011-05-21 Thread DebUggEr
Thats what droid reader and pdf readers do, they use c library in jni folder 
of their source. 

Can you show me how to solve this one? I believe you dont understand the 
full scale of this project. Its time taking and cant be done through emails 
or even skype. 

I also have a hint that you are requiring a single file to be output as 
executable in android rather than a full pdf reader. Then you can convert 
them to images and put them in Image view. If not then you are looking for a 
integration like in windows but thing like that isnt possible without a 
viewer. So it wont speed up.

On Sunday, May 22, 2011 6:00:33 AM UTC+5, khanh le wrote:

 To be specific, I need a lib to read pdf files and the output of each page 
 will be an image stream.

 On Sun, May 22, 2011 at 7:55 AM, khanh_qhi™ khanhq...@gmail.com wrote:

 Hi,
 My problem is that I want to read an ebook file(PDF extension), but not 
 depend on and pdf viewer app(because it may be slow down program).
 So, I need an open source to view it, I think it will faster than I use on 
 pdf viewer application.
 Can you show me how to solve this one?


 On Sat, May 21, 2011 at 10:45 PM, DebUggEr sjklite...@gmail.com wrote:

 Khanh,

 Please search code.google.com for droid reader. It is full 
 implementation for you. Of course if you are a beginner you will need 
 someone to guide you how to understand it.

 Also, try to put more understanding to your questions. 

 Sincerely,
 Jehandad

 -- 
 You received this message because you are subscribed to the Google
 Groups Android Developers group.
 To post to this group, send email to android-d...@googlegroups.com
 To unsubscribe from this group, send email to
 android-develop...@googlegroups.com
 For more options, visit this group at
 http://groups.google.com/group/android-developers?hl=en




 -- 
 Regards,
 Khanh.




 -- 
 Regards,
 Khanh.


-- 
You received this message because you are subscribed to the Google
Groups Android Developers group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

[android-developers] Re: Sharing data across Activities

2011-03-09 Thread DebUggEr
Seems like heres the answer. I am not an expert but do consider and let me 
know too.

ANDROID.APP.APPLICATION CLASS

Each Android application can have at most one android.app.Applicationassociated 
with it. You are responsible for sub-classing the Application Class, and it 
is used to maintain a global state of the application across all Activites. 
Conceptually, you can think of it as a non-static singleton its life cycle 
being managed by Android OS.
*Benefits:*

   - Gives you complete control over the management of application 
   life-cycle, so resources can be properly initialised and disposed of.
   - Provides a single entry point where *any* Activity or Service within 
   the application can gain access to the desired object

*Drawbacks:*

   - Can only expose information to Activities and Services within the 
   application

-- 
You received this message because you are subscribed to the Google
Groups Android Developers group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

[android-developers] Re: onBufferingUpdate What is the progress argument

2011-01-10 Thread DebUggEr
That is a good guess. I will experiment it.

-- 
You received this message because you are subscribed to the Google
Groups Android Developers group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

[android-developers] Re: onBufferingUpdate What is the progress argument

2011-01-08 Thread DebUggEr
I myself dont get what the situation is, the mediaplayer isnt seeking 
correctly because of it.

-- 
You received this message because you are subscribed to the Google
Groups Android Developers group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

[android-developers] Answer Incoming call automatically.

2010-12-03 Thread DebUggEr
Well I need to do to things,

1. automatically answer the calls which are in the blacklist
2. Receive all other calls through the usual android call receiver.

I know the first thing is to register intent, but since no activity
can handle it, I need to use services and a media recorder somehow in
conjunction.

Any ideas??

-- 
You received this message because you are subscribed to the Google
Groups Android Developers group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en