Got it. Thanks all for the replies.
2009/7/15 Dianne Hackborn <[email protected]> > No you would do this for each activity. Again, I am suggesting to not use > Application, or if you do use it to make your own version that will work > with whatever code is running in its process. > > > On Tue, Jul 14, 2009 at 1:46 PM, Ronghui Zhu <[email protected]>wrote: > >> Thanks. >> >> 2009/7/15 Dianne Hackborn <[email protected]> >> >>> On Tue, Jul 14, 2009 at 12:59 PM, magicpig <[email protected]>wrote: >>> >>>> Can you provide the APIs to get the ActivityInfo? >>> >>> >>> >>> http://developer.android.com/reference/android/content/pm/PackageManager.html#getActivityInfo%28android.content.ComponentName,%20int%29 >>> >>> >> So, in Application#onCreate, I should >> 1. Get PackageManager >> 2. call getActivityInfo >> (ComponentName<http://developer.android.com/reference/android/content/ComponentName.html>className, >> int flags)by specifying the className to my activity(I have specify a >> different >> process name) >> 3. get the processName >> >> But this sounds that we only get the process' name for that Component, not >> the running activity. >> >> >> >>> > really seems like a hack. Why not have a single Application object, >>>> that >>>> > allows others to register to receive the callbacks they are >>>> interested in? >>>> It seems that Application class is the first one to run when the >>>> application starts. >>>> Here,I assume that others mean all the components including activities/ >>>> services/... >>>> So, would you mind give out an example for it? >>> >>> >>> Just write a single CustomApplication class everyone uses, with a method >>> to add a callback for onLowMemory(). >>> >>> For creation, us normal Java stuff: >>> >>> class MyGlobals { >>> static MyGlobals sGlobals; >>> >>> static MyGlobals getInstance() { >>> // Note: use synchronization if this will be accessed from multiple >>> threads. >>> >>> if (sGlobals != null) return sGlobals; >>> >>> sGlobals = new MyGlobals(); >>> return sGlobals; >>> } >>> } >>> >>> >>> >>>> >>>> >>>> Really appreciate the help >>>> > >>>> > (And honestly, you don't need the Application object. Stuff you do in >>>> > onCreate() you can do the first time someone accesses whatever global >>>> object >>>> > they want... which can actually be better, to avoid initializing >>>> things >>>> > that you don't need. And there is also a broadcast that gets sent >>>> when >>>> > onLowMemory is called, so you can just register for that.) >>>> > >>>> > >>>> > >>>> > On Tue, Jul 14, 2009 at 11:35 AM, magicpig <[email protected]> >>>> wrote: >>>> > > On Tue, Jul 14, 2009 at 12:12 AM, magicpig <[email protected]> >>>> > > wrote: >>>> > >>>> > > Thanks Dianne for the quick reply. >>>> > >>>> > > My two Application.java do some more things than having the >>>> > > statics: >>>> > > 1. own the ability to store current activity for use in all the >>>> > > activities in the same process. (In the former description, I >>>> just >>>> > > talked about two for simple). >>>> > > 2. Creating some instances for later use(maybe can be moved to >>>> > > statics) >>>> > >>>> > > So, if there is a way for replacing this easily, I am happy to >>>> do. >>>> > >>>> > > BTW, I think we can read the process name, right? >>>> > >>>> > > Thanks a again. >>>> > >>>> > > On Jul 15, 1:58 am, magicpig <[email protected]> wrote: >>>> > > > Thanks for the reply. >>>> > >>>> > > > I am trying hard to merge them together and the Application logic >>>> > > > seems a little more than setting the globals, such performing >>>> > > > differently on onLowMemory, onTerminate and >>>> onConfigurationChanged. >>>> > >>>> > > > So,is it possible to get the intent that starts the activity or >>>> the >>>> > > > different process name in Application#onCreate? >>>> > >>>> > > > Thanks >>>> > >>>> > > > On Jul 14, 2:20 pm, Dianne Hackborn <[email protected]> wrote: >>>> > >>>> > > > > Sorry, you can't do that. There are really very few reasons to >>>> have a >>>> > > > > custom Application anyway. I would generally suggest staying >>>> away from >>>> > > it, >>>> > > > > and just using statics for your globals. >>>> > >>>> > > > > On Mon, Jul 13, 2009 at 11:17 PM, magicpig < >>>> [email protected]> >>>> > > wrote: >>>> > > > > > HI, >>>> > >>>> > > > > > I need two activities run in different processes in the >>>> same >>>> > > > > > application. Now I have made it work by specifying the >>>> different >>>> > > > > > process name in "android:process". >>>> > >>>> > > > > > But I met a problem, from >>>> > >>>> > > >>>> http://developer.android.com/guide/topics/manifest/application-elemen. >>>> .. >>>> > > > > > , >>>> > > > > > we have only one superclass of Application will run before the >>>> > > > > > activity starts(I have tested it, and each time a after new >>>> processes >>>> > > > > > start, this Application(its superclass) will run before >>>> activity). >>>> > > > > > But, my two activities have two different superclasses of >>>> > > > > > Applications. So, how to make Applications for different >>>> activities >>>> > > > > > run for its corresponding activity? >>>> > >>>> > > > > > If there is no way to use different Application class >>>> for >>>> > > > > > different activity, how can I make a flag for the common >>>> Application >>>> > > > > > superclass to judge which process(by getting its name) is >>>> running? >>>> > >>>> > > > > > BTW, the two activities were on the separated development >>>> flow >>>> > > > > > and I am trying to merge them. >>>> > >>>> > > > > > Thanks a lot. >>>> > >>>> > > > > -- >>>> > > > > Dianne Hackborn >>>> > > > > Android framework engineer >>>> > > > > [email protected] >>>> > >>>> > > > > Note: please don't send private questions to me, as I don't have >>>> time >>>> > > to >>>> > > > > provide private support, and so won't reply to such e-mails. >>>> All such >>>> > > > > questions should be posted on public forums, where I and others >>>> can see >>>> > > and >>>> > > > > answer them. >>>> > >>>> > -- >>>> > Dianne Hackborn >>>> > Android framework engineer >>>> > [email protected] >>>> > >>>> > Note: please don't send private questions to me, as I don't have time >>>> to >>>> > provide private support, and so won't reply to such e-mails. All such >>>> > questions should be posted on public forums, where I and others can >>>> see and >>>> > answer them. >>>> >>> >>> >>> >>> -- >>> Dianne Hackborn >>> Android framework engineer >>> [email protected] >>> >>> >>> Note: please don't send private questions to me, as I don't have time to >>> provide private support, and so won't reply to such e-mails. All such >>> questions should be posted on public forums, where I and others can see and >>> answer them. >>> >>> >> > > > -- > Dianne Hackborn > Android framework engineer > [email protected] > > Note: please don't send private questions to me, as I don't have time to > provide private support, and so won't reply to such e-mails. All such > questions should be posted on public forums, where I and others can see and > answer them. > > --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Android Developers" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/android-developers?hl=en -~----------~----~----~----~------~----~------~--~---

