[android-developers] Re: sharing data between activities.
A friend gave my an idea, I thought if doing a query twice in the past, one for the first list and the other once a row was chosen, since i don't use projects parameter the queries are not efficient, however if for the first list i need just two rows and for the second i take only a single column (or if i'll use certain columns from certain rows) it'll be more efficient so all i need to do is pass on the _ID parameter in the intent. Of course this is a solution for cursors only and for certain type of queries, not for all of them. For bigger amount of data needs to be shared among activities maybe the service solution remains best... On Apr 7, 6:10 pm, poohtbear eyaltg...@gmail.com wrote: I agree with you, static members don't have to be a manace regarding GC, but they do carry the memory leaks danger if you don't treat them well, i close the cursor and null the instance in onDestroy and recreate it in onCreate. However in a big complicated program with a lot of code it's a needless hazard, i do agree to that. Doesn't the extra service adds to the code complexity ? adds to the accumulated application memory, after all it's also a component that consumes resources. I find it kind of frustrating that i cannot get instance of an activity or one of it's inner classes without a static member, as i said they live in the same memory space... On Apr 7, 6:03 pm, Mark Murphy mmur...@commonsware.com wrote: Isn't that an overkill ? create a service to share a single cursor between 2 activities ? if it were a generic service that i used to share many cursor from many queries (lets say it's a query management service) and several activities will use it then i can understand the efficiency and code simplicity in it, for more simple examples it sounds like an overkill. The other options you cited are bad for performance (putting the Cursor in an Intent extra) or are risky from a garbage collection standpoint (using mutable static data members). -- Mark Murphy (a Commons Guy)http://commonsware.com Android App Developer Books:http://commonsware.com/books.html -- 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 To unsubscribe, reply using remove me as the subject.
[android-developers] Re: sharing data between activities.
Isn't that an overkill ? create a service to share a single cursor between 2 activities ? if it were a generic service that i used to share many cursor from many queries (lets say it's a query management service) and several activities will use it then i can understand the efficiency and code simplicity in it, for more simple examples it sounds like an overkill. On Apr 7, 5:39 pm, Mark Murphy mmur...@commonsware.com wrote: Is there another sharing method that i don't know off Use a Service. Have the Service manage the querying. Have activities retrieve the Cursor from the Service using an API supplied via bindService(). -- Mark Murphy (a Commons Guy)http://commonsware.com Android App Developer Books:http://commonsware.com/books.html -- 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 To unsubscribe, reply using remove me as the subject.
Re: [android-developers] Re: sharing data between activities.
Isn't that an overkill ? create a service to share a single cursor between 2 activities ? if it were a generic service that i used to share many cursor from many queries (lets say it's a query management service) and several activities will use it then i can understand the efficiency and code simplicity in it, for more simple examples it sounds like an overkill. The other options you cited are bad for performance (putting the Cursor in an Intent extra) or are risky from a garbage collection standpoint (using mutable static data members). -- Mark Murphy (a Commons Guy) http://commonsware.com Android App Developer Books: http://commonsware.com/books.html -- 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 To unsubscribe, reply using remove me as the subject.
[android-developers] Re: sharing data between activities.
I agree with you, static members don't have to be a manace regarding GC, but they do carry the memory leaks danger if you don't treat them well, i close the cursor and null the instance in onDestroy and recreate it in onCreate. However in a big complicated program with a lot of code it's a needless hazard, i do agree to that. Doesn't the extra service adds to the code complexity ? adds to the accumulated application memory, after all it's also a component that consumes resources. I find it kind of frustrating that i cannot get instance of an activity or one of it's inner classes without a static member, as i said they live in the same memory space... On Apr 7, 6:03 pm, Mark Murphy mmur...@commonsware.com wrote: Isn't that an overkill ? create a service to share a single cursor between 2 activities ? if it were a generic service that i used to share many cursor from many queries (lets say it's a query management service) and several activities will use it then i can understand the efficiency and code simplicity in it, for more simple examples it sounds like an overkill. The other options you cited are bad for performance (putting the Cursor in an Intent extra) or are risky from a garbage collection standpoint (using mutable static data members). -- Mark Murphy (a Commons Guy)http://commonsware.com Android App Developer Books:http://commonsware.com/books.html -- 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 between activities
Hi, data size is 960987 bytes, logcat: V/ImageCaptureCallback( 8863): onpicturetaken...@43678fb0 length = 960987 I'll try to increase heap size next, thx. olli On Aug 15, 8:24 am, powerbyte powerb...@gmail.com wrote: Hello Olli, what is the size of byte[]data? may be problem with the heap size. In logcat output, is something like grow heap? if yes, try with increasing heap size. pb On Aug 14, 2:22 pm, Elias elias.va...@googlemail.com wrote: I have tried to share betweeb two simpleactivities: On parent activity, I'll start ImageCapture Activity: IntentcameraIntent = newIntent(); cameraIntent.setClass(this, ImageCapture.class); cameraIntent.putExtra(cameraData, null); //not sure why this is here? startActivityForResult(cameraIntent, 1); @Override protected void onActivityResult(int requestCode, int resultCode, Intentdata) { CharSequence text = onActivityResult requestCode + requestCode + resultCode + resultCode + data +data; int duration = Toast.LENGTH_LONG; Toast toast = Toast.makeText(this, text, duration); toast.show(); } And on camera Activity (I have inner class which implements PictureCallback): �...@override public void onPictureTaken(byte[]data, Camera camera) { try { IntentresultIntent = newIntent(); resultIntent.putExtra(cameraData,data); setResult(Activity.RESULT_OK,resultIntent); finish(); } catch (Exception ex) { setResult(Activity.RESULT_CANCELED); finish(); } } It seems that onActivityResult method is never called, what am I missing here? Camera activity is closed and first activity is shown again but onActivityResult is not called. It works perfectly fine (onActivityResult is called and toast is displayed) if do following on cameraintent: @Override public void onPictureTaken(byte[]data, Camera camera) { try { //IntentresultIntent = newIntent(); //resultIntent.putExtra(cameraData,data); setResult(Activity.RESULT_OK); finish(); } catch (Exception ex) { setResult(Activity.RESULT_CANCELED); finish(); } With code above Activity.RESULT_OK (-1) is returned to onActivityResult method. I'm testing with HTC Hero. Cheers Olli On 7 elo, 17:48, elpix1 elp...@gmail.com wrote: Another way to sharedatabetweenactivitiesin the same process is to use the Application class: http://developer.android.com/reference/android/app/Application.html You have to specify the name of your Application class in the manifest and the framework will create only an instance of this class, which will live while the application process is running. In any activity, you can get the reference for your application instance using: Application a = getApplication(); On Jul 22, 10:49 am, Per Sandström pg.sandst...@gmail.com wrote: So far I have been using SharedPreferences to sharedatabetween 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:Activitiesdon't have constructors! How do I senddata to them from their parent activity??? Regards, Per Sandström- 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 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 between activities
I have tried to share betweeb two simple activities: On parent activity, I'll start ImageCapture Activity: Intent cameraIntent = new Intent(); cameraIntent.setClass(this, ImageCapture.class); cameraIntent.putExtra(cameraData, null); //not sure why this is here? startActivityForResult(cameraIntent, 1); @Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { CharSequence text = onActivityResult requestCode + requestCode + resultCode + resultCode + data + data; int duration = Toast.LENGTH_LONG; Toast toast = Toast.makeText(this, text, duration); toast.show(); } And on camera Activity (I have inner class which implements PictureCallback): @Override public void onPictureTaken(byte[] data, Camera camera) { try { Intent resultIntent = new Intent(); resultIntent.putExtra(cameraData, data); setResult(Activity.RESULT_OK,resultIntent); finish(); } catch (Exception ex) { setResult(Activity.RESULT_CANCELED); finish(); } } It seems that onActivityResult method is never called, what am I missing here? Camera activity is closed and first activity is shown again but onActivityResult is not called. It works perfectly fine (onActivityResult is called and toast is displayed) if do following on camera intent: @Override public void onPictureTaken(byte[] data, Camera camera) { try { //Intent resultIntent = new Intent(); //resultIntent.putExtra(cameraData, data); setResult(Activity.RESULT_OK); finish(); } catch (Exception ex) { setResult(Activity.RESULT_CANCELED); finish(); } With code above Activity.RESULT_OK (-1) is returned to onActivityResult method. I'm testing with HTC Hero. Cheers Olli On 7 elo, 17:48, elpix1 elp...@gmail.com wrote: Another way to share data between activities in the same process is to use the Application class: http://developer.android.com/reference/android/app/Application.html You have to specify the name of your Application class in the manifest and the framework will create only an instance of this class, which will live while the application process is running. In any activity, you can get the reference for your application instance using: Application a = getApplication(); On Jul 22, 10:49 am, Per Sandström pg.sandst...@gmail.com 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, Per Sandström --~--~-~--~~~---~--~~ 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 between activities
Hello Olli, what is the size of byte[] data? may be problem with the heap size. In logcat output, is something like grow heap? if yes, try with increasing heap size. pb On Aug 14, 2:22 pm, Elias elias.va...@googlemail.com wrote: I have tried to share betweeb two simpleactivities: On parent activity, I'll start ImageCapture Activity: Intent cameraIntent = new Intent(); cameraIntent.setClass(this, ImageCapture.class); cameraIntent.putExtra(cameraData, null); //not sure why this is here? startActivityForResult(cameraIntent, 1); @Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { CharSequence text = onActivityResult requestCode + requestCode + resultCode + resultCode + data + data; int duration = Toast.LENGTH_LONG; Toast toast = Toast.makeText(this, text, duration); toast.show(); } And on camera Activity (I have inner class which implements PictureCallback): �...@override public void onPictureTaken(byte[] data, Camera camera) { try { Intent resultIntent = new Intent(); resultIntent.putExtra(cameraData, data); setResult(Activity.RESULT_OK,resultIntent); finish(); } catch (Exception ex) { setResult(Activity.RESULT_CANCELED); finish(); } } It seems that onActivityResult method is never called, what am I missing here? Camera activity is closed and first activity is shown again but onActivityResult is not called. It works perfectly fine (onActivityResult is called and toast is displayed) if do following on camera intent: @Override public void onPictureTaken(byte[] data, Camera camera) { try { //Intent resultIntent = new Intent(); //resultIntent.putExtra(cameraData, data); setResult(Activity.RESULT_OK); finish(); } catch (Exception ex) { setResult(Activity.RESULT_CANCELED); finish(); } With code above Activity.RESULT_OK (-1) is returned to onActivityResult method. I'm testing with HTC Hero. Cheers Olli On 7 elo, 17:48, elpix1 elp...@gmail.com wrote: Another way to share data betweenactivitiesin the same process is to use the Application class: http://developer.android.com/reference/android/app/Application.html You have to specify the name of your Application class in the manifest and the framework will create only an instance of this class, which will live while the application process is running. In any activity, you can get the reference for your application instance using: Application a = getApplication(); On Jul 22, 10:49 am, Per Sandström pg.sandst...@gmail.com 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:Activitiesdon't have constructors! How do I send data to them from their parent activity??? Regards, Per Sandström- 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 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 between activities
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 roman.baumgaert...@t-mobile.com 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 medicalsou...@gmail.com 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 pg.sandst...@gmail.com 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 powerb...@gmail.com 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 pg.sandst...@gmail.com 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 nikolatesl...@yahoo.com wrote: On Jul 22, 1:19 pm, Roman roman.baumgaert...@t-mobile.com 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ömpg.sandst...@gmail.com 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
[android-developers] Re: Sharing data between activities
sylvestercaro...@gmail.com wrote: 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. It can. However, AFAIK, database connections to SQLite are cheap, so you may just want to have each activity get its own connection. -- Mark Murphy (a Commons Guy) http://commonsware.com | http://twitter.com/commonsguy Warescription: Three Android Books, Plus Updates, $35/Year --~--~-~--~~~---~--~~ 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 between activities
Another way to share data between activities in the same process is to use the Application class: http://developer.android.com/reference/android/app/Application.html You have to specify the name of your Application class in the manifest and the framework will create only an instance of this class, which will live while the application process is running. In any activity, you can get the reference for your application instance using: Application a = getApplication(); On Jul 22, 10:49 am, Per Sandström pg.sandst...@gmail.com 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, Per Sandström --~--~-~--~~~---~--~~ 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 between activities
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 powerb...@gmail.com 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 pg.sandst...@gmail.com 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 nikolatesl...@yahoo.com wrote: On Jul 22, 1:19 pm, Roman roman.baumgaert...@t-mobile.com 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ömpg.sandst...@gmail.com 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 same application, then just use a global object and pass that around (singleton or such). Not too tough. -niko- 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 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 between activities
I haven't tried this but its another alternative. If your application runs multiple activities inside one process I assume you can create a class that has public static variables. Than you can access these variables in any of the process activities. Might be wrong but I think it could work... -Jona On Aug 5, 3:35 am, Per Sandström pg.sandst...@gmail.com 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 powerb...@gmail.com 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 pg.sandst...@gmail.com 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 nikolatesl...@yahoo.com wrote: On Jul 22, 1:19 pm, Roman roman.baumgaert...@t-mobile.com 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ömpg.sandst...@gmail.com 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 same application, then just use a global object and pass that around (singleton or such). Not too tough. -niko- 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 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 between activities
Start it with startActivityForResult(), and return the data with setResult(). 2009/8/5 Per Sandström pg.sandst...@gmail.com 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 powerb...@gmail.com 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 pg.sandst...@gmail.com 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 nikolatesl...@yahoo.com wrote: On Jul 22, 1:19 pm, Roman roman.baumgaert...@t-mobile.com 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ömpg.sandst...@gmail.com 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 same application, then just use a global object and pass that around (singleton or such). Not too tough. -niko- Hide quoted text - - Show quoted text - -- Dianne Hackborn Android framework engineer hack...@android.com 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 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 between activities
yes, for returning values from second activity call setData(,,) from second activity before finishing activity. And in first activity instead of startActivity(..) call startActivityForResult(..) and override onActivityResult(...) for Example: In parent activity, declare a variable for aaa child activity static final int AAA_ACTIVITY_RETURN = 0; static final int BBB_ACTIVITY_RETURN = 1; //another bbb child activity for com.sample.bbb.class ( for Multiple activities ) Intent intent = new Intent(this,com.sample.aaa.class); //aaa is child activity intent.putExtra(ARG1,value1); intent.putExtra(ARG2,value2); startActivityForResult(intent, AAA_ACTIVITY_RETURN ); protected void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); if(requestCode == AAA_ACTIVITY_RETURN ) { String sVal1 = data.getStringExtra( Return1 ); String sVal2 = data.getStringExtra( Return2 ); } if(requestCode == BBB_ACTIVITY_RETURN) { // handle values from bbb child activity } } In Child Activity some_Activity_close_funnction() { Intent data = new Intent(); data.putExtra(Return1,Val1); data.putExtra(Return2,val1); setResult(RESULT_OK,data); finish(); } -pb 2009/8/5 Per Sandström pg.sandst...@gmail.com 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 powerb...@gmail.com 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 pg.sandst...@gmail.com 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 nikolatesl...@yahoo.com wrote: On Jul 22, 1:19 pm, Roman roman.baumgaert...@t-mobile.com 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ömpg.sandst...@gmail.com 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 same application, then just use a global object and pass that around (singleton or such). Not too tough. -niko- 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 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 between activities
-Jona, the idea with static variables would 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 medicalsou...@gmail.com wrote: I haven't tried this but its another alternative. If your application runs multiple activities inside one process I assume you can create a class that has public static variables. Than you can access these variables in any of the process activities. Might be wrong but I think it could work... -Jona On Aug 5, 3:35 am, Per Sandström pg.sandst...@gmail.com 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 powerb...@gmail.com 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 pg.sandst...@gmail.com 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 nikolatesl...@yahoo.com wrote: On Jul 22, 1:19 pm, Roman roman.baumgaert...@t-mobile.com 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ömpg.sandst...@gmail.com 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 same application, then just use a global object and pass that around (singleton or such). Not too tough. -niko- 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 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 between activities
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 nikolatesl...@yahoo.com wrote: On Jul 22, 1:19 pm, Roman roman.baumgaert...@t-mobile.com 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ömpg.sandst...@gmail.com 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 same application, then just use a global object and pass that around (singleton or such). Not too tough. -niko --~--~-~--~~~---~--~~ 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 between activities
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 pg.sandst...@gmail.com 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 nikolatesl...@yahoo.com wrote: On Jul 22, 1:19 pm, Roman roman.baumgaert...@t-mobile.com 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ömpg.sandst...@gmail.com 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 same application, then just use a global object and pass that around (singleton or such). Not too tough. -niko- 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 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 between activities
As already mentioned earlier, you could also use Intents which are very lightweight. You are able to attach also a data record to your intent using the method putextra(). http://developer.android.com/reference/android/content/Intent.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 Aug 4, 6:31 am, Per Sandström pg.sandst...@gmail.com 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 nikolatesl...@yahoo.com wrote: On Jul 22, 1:19 pm, Roman roman.baumgaert...@t-mobile.com 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ömpg.sandst...@gmail.com 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 same application, then just use a global object and pass that around (singleton or such). Not too tough. -niko --~--~-~--~~~---~--~~ 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 between activities
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, Per Sandström pg.sandst...@gmail.com 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, Per Sandström --~--~-~--~~~---~--~~ 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 between activities
On Jul 22, 1:19 pm, Roman roman.baumgaert...@t-mobile.com 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, Per Sandström pg.sandst...@gmail.com 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, Per Sandström Hi, If both activities are in the same application, then just use a global object and pass that around (singleton or such). Not too tough. -niko --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---