I have a similar question. Basically I have an app with several activities, each needs to read different data from a common local SQLite db. This data doesn't have to be accessed outside of the application itself - hence I decided against using a content provider. I was thinking of using the application instance to hold the database instance, as I thought that each activity would be able to access this to retrieve it's data (I didn't want to open and close the db in each activity for performance reasons) - but I'm not sure if the activity can reference this application instance. I was going to call back on intents, passing the database instance to each invoked activity as needed - but I was wondering if there is a better way. Any thought?
On Aug 5, 8:25 pm, Roman <[email protected]> wrote: > -Jona, the idea with staticvariableswould work (without having > efficiency in mind). The only problem I see is when you are working in > a threaded environment. Then you might have to make sure that your > implementation is thread safe. > > -- > Roman Baumgaertner > Sr. SW Engineer-OSDC > ·T· · ·Mobile· stick together > The views, opinions and statements in this email are those of the > author solely in their individual capacity, and do not necessarily > represent those of T-Mobile USA, Inc. > > On Aug 5, 10:16 am, Moto <[email protected]> wrote: > > > > > I haven't tried this but its another alternative. > > > If yourapplicationruns multiple activities inside one process I > > assume you can create a class that has public staticvariables. Than > > you can access thesevariablesin any of the process activities. > > > Might be wrong but I think it could work... > > > -Jona > > > On Aug 5, 3:35 am, Per Sandström <[email protected]> wrote: > > > > thanks man, that is an excellent way of explaining so even an android- > > > beginner can understand. Is there a similar way of returning data to > > > the first activity when the second activity has finished running, > > > corresponding to javas "return value1;"? > > > > Regards > > > Per Sandström > > > > On 4 Aug, 17:44, powerbyte <[email protected]> wrote: > > > > > Hello > > > > > >>To summarize: Activities don't have constructors! How do I send data > > > > >>to them from their parent activity??? > > > > > we can send data from parent activity to childs, using Intent > > > > > for example: > > > > > In parent activity, > > > > > Intent intent = new Intent(this,com.sample.aaa.class); //aaa is > > > > child activity > > > > intent.putExtra("ARG1","value1"); > > > > intent.putExtra("ARG2","value2"); > > > > StartActivity(intent); > > > > > In Child activity (aaa) use Bundle to get the data > > > > > public void onCreate(Bundle som) { > > > > super.onCreate(som); > > > > > Intent intent = this.getIntent(); > > > > Bundle b = intent.getExtras(); > > > > String sVal1 = b.getString("ARG1"); > > > > String sVal2 = b.getString("ARG2"); > > > > .... > > > > ... > > > > > } > > > > > -pb > > > > > On Aug 4, 6:31 pm, Per Sandström <[email protected]> wrote: > > > > > > but how do I create and pass this global object? I cant do it like I > > > > > do in java or other programming languages where . AIDL is an > > > > > alternative, but it still seems overkill for a small app. > > > > > > regards > > > > > Per Sandström > > > > > > On Jul 22, 10:50 pm, niko20 <[email protected]> wrote: > > > > > > > On Jul 22, 1:19 pm, Roman <[email protected]> wrote: > > > > > > > > Android supports multiple IPC mechanisms. > > > > > > > > You can use the Intent mechanism as well as the AIDL mechanism for > > > > > > > doing this. The AIDL approach is more complex but offers you also > > > > > > > more > > > > > > > flexibility to pass objects. > > > > > > > > Find information about this topic on > > > > > > > >http://developer.android.com/guide/developing/tools/aidl.html > > > > > > > > -- > > > > > > > Roman Baumgaertner > > > > > > > Sr. SW Engineer-OSDC > > > > > > > ·T· · ·Mobile· stick together > > > > > > > The views, opinions and statements in this email are those of the > > > > > > > author solely in their individual capacity, and do not necessarily > > > > > > > represent those of T-Mobile USA, Inc. > > > > > > > > On Jul 22, 6:49 am, PerSandström<[email protected]> wrote: > > > > > > > > > So far I have been using SharedPreferences to share data between > > > > > > > > activities. But I would very much like to find a better way. I > > > > > > > > would > > > > > > > > simply like both Activity1 and Activity2 to share Object1. > > > > > > > > Activity1 > > > > > > > > will create Object1 and then start Activity2. What is the > > > > > > > > smartest way > > > > > > > > to give Activity2 a pointer to Object1? > > > > > > > > > To summarize: Activities don't have constructors! How do I send > > > > > > > > data > > > > > > > > to them from their parent activity??? > > > > > > > > > Regards, > > > > > > > > PerSandström > > > > > > > Hi, > > > > > > > If both activities are in the sameapplication, then just use a > > > > > > global > > > > > > object and pass that around (singleton or such). Not too tough. > > > > > > > -niko- Hide quoted text - > > > > > > - Show quoted text -- Hide quoted text - > > - Show quoted text - --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---

