Android :: Sharing Domain Objects Between Activities
Jan 11, 2010
I have written my application logic in domain objects (to enable multiple user interfaces and porting to other platforms), and am now lookng at implementing Activities for the user interface.
Considering that each activity needs to serialise its state, what is the best way to ensure my domain objects are only serialised once?
View 1 Replies
Oct 26, 2010
The FAQ mentions a method of passing objects around activities. (It is not clear to me): "A HashMap of WeakReferences to Objects. You can also use a HashMap of WeakReferences to Objects with Long keys. When an activity wants to pass an object to another activity, it simply puts the object in the map and sends the key (which is a unique Long based on a counter or time stamp) to the recipient activity via intent extras. The recipient activity retrieves the object using this key.".................
View 7 Replies
View Related
Aug 30, 2010
I want to pass an object from Activity B to Activity A. Scenario:
- Activity A calls Activity B
- User selects item in Activity B
- Activity B passes an object to Activity A
How do I accomplish this? And in which method do I read in the passed object in Activity A?
View 2 Replies
View Related
Oct 18, 2009
I am trying to pass a user defined object to another activity Bundle bundle = new Bundle(); bund.putSerializable("myData", myData); intent.putExtra("bundle", bundle); where myData class implements Serializable interface. I am getting following error: java.lang.RuntimeException: Parcelable encountered IOException writing serializable object how to pass complex objects between activities?
View 7 Replies
View Related
Jul 29, 2010
What is proper way to exchange data or objects between different Android Activities?
Welcome screen <-> Main Screen <-> Startup routines <-> Processing data <-> Settings
Is it normal/recommended to have more than one activity in Android app? in my opinion, it's somehow strange to have this model of data exchange inside application
View 3 Replies
View Related
Nov 16, 2009
I am trying to pass a custom object to one activity from another. What I would like to use is the HashMap of WeakReferences, but the description isn't clear, at least to me. From above URL: "A HashMap of WeakReferences to Objects. You can also use a HashMap of WeakReferences to Objects with Long keys. When an activity wants to pass an object to another activity, it simply puts the object in the map and sends the key (which is a unique Long based on a counter or time stamp) to the recipient activity via intent extras. The recipient activity retrieves the object using this key."
MyObject object = new MyObject(); HashMap map = new HashMap(); WeakReference reference = new WeakReference(object); map.put(reference.hashCode(), reference);
Intent i = new Intent(myIntent); i.putExtra(map);
I know this is probably way off but I can't figure out how this is intended to be implemented based on the description. Are the keys hashcodes, user defined, or what? It sounds like all that is passed is a HashMap containing the key values but how is the object retrieved with just the key? I couldn't find any code examples or useful documentation on this method of passing objects
View 3 Replies
View Related
Jun 29, 2010
How to pass socket, inputstream, outputstream objects between activities
View 1 Replies
View Related
Nov 24, 2010
It would be nice if StackOverflow had a section where we could post tutorials like mine so that I can answer literally hundreds of questions that have been asked here with a single blow. See... every day I read questions about how to pass complex objects between activities, how to save state so that your app can resume after orientation change, how to update listviews when the data changes, etc, etc. Here is the second part of a tutorial series I posted on my blog... I hope that you actually read it... because I haven't seen any examples like it anywhere... and it has changed how I think about developing for Android across the board. The question is... is there a downside or negative affect of developing like this?
Beyond Smart Lists - How Observable Singletons change the game. Please read through both of these tutorials carefully... I will answer any questions about it here that I can... I really want to know what you think about this and if it might solve issues for you. NOTE TO MODERATORS: there are no advertisements of any kind on my blog.. so don't just close this because you think I am spamming somehow... I am not going to duplicate my post here.
View 1 Replies
View Related
Apr 7, 2010
I was playing a bit with adapters cursors and activities. Let's assume i have a cursor containing a query I've made (it doesn't matter if it's to DB or content provider). Now lets assume i bind some of the data (first two rows) to a list activity. Every click on one of those items should open a new list activity (i pass on the cursor index in the activity bundle). Now the question is, which sharing method will be most efficient and right from code point of view ?
1. I thought of trying to send the cursor object in the intent itself (hoping it implemented runnable) but I'm not so sure it's that efficient since the query may contain many rows which will need to be parceled, and i the other intents uses only a few (say 4-5 columns of each row) it's a real waste.
2. Thought of trying to create the array list for my other list screen adapter and serialize it to the intent (again use serialize and intent to pass on the data) but again i fear for efficiency penalty.
3. my last solution was to use static cursor member in my first activity, with package permission, it will work and be relatively efficient, but I'm not so sure regarding memory efficiency and code structure, i'm not fond of using static variables in any case.
Is there another sharing method that i don't know off, if two activities share the same process and application, then they also share memory space, then it should be easy to pass variables from one to another, the question is what's the easiest way without serializing ?
View 6 Replies
View Related
Aug 10, 2010
I did some digging, but couldn't find a clear answer. I have an application with TabActivity as the main activity. I have some computing and network communication that needs to be done when user clicks on the big red jolly "DO IT" button. One tab hosts the form with "DO IT" button, while the other tabs display the results from computing (each tab displays different part of results). The computing is done as AsyncTask as it's supposed to be (afaik).
Now the question is, what is the best way to share the results between the tabbed activities? It can be done with ContentProvider + database from what I have read, although that seems like a bit too much for my needs. I have also considered an option to save the results to some cache file activities could read in onCreate, onResume etc and display the data. Are there any other convenient ways to share the data? (To make it more clear, the data aren't simple, so doing it through preferences etc is impossible.)
View 5 Replies
View Related
Mar 13, 2009
I was looking out for ways to share data between various activities that one may need to create for his applications . Using "Parcel" and Bundle one can do data exchange , but looks like this is a bit cumbersome process specifically if you have to share large array objects with too many fields.
As android.app.Application maintains global state for the application , we can use this class to store global data and access it across activities. Is this a good way ? Are there any implications on allocating large objects in the your class which extends from android.app.Application ?
View 6 Replies
View Related
Oct 7, 2009
I have an app with two activities.
Both activities among other functions have to perform the same calculation on data, so each activity include the same code to perform the calculation.
Is it possible to only have the similar code in a separate activity and be accessed by the other two activities instead of duplicating the code twice?
View 15 Replies
View Related
Nov 21, 2010
I think the following scenario is common, but I can't figure the way to implement it:
We have three Activities, and one database. We ask the user for an input to search in the database. The query should get none, one or may results.
If you get none you simple inform the user.
If you get only one, you show it in a new activity with the right view.
If you get many you show them in a list to let the user to chose the right one and then you pass that to the activity which with show the data in the case of one result only.
The problem is that, in order to know the number of results, you need to do the query (and get the cursor) in the first activity. And in the case you get more than one result you need to send the data (pass the cursor?)to the list acitivty. Doing the query again in the list activity can't be right, right?
I'm aware that you can share cursors by using a content provider, but as the activities are from the same application and the data is private (useless outside), don't see the point of making it avaliable to anyone else.
I read here around that you can crate a parcelable cursor and send it in bundle, but I'm not sure if that is the right use.
View 1 Replies
View Related
Nov 24, 2010
I have a Weather app with four Activities. The main/launcher activity is 'invisible' using...
android:theme="@android:style/Theme.Translucent.NoTitleBar"`
Aand is simply used to do a few checks (whether this is a new install, whether a network connection is available etc) before firing off one of the other Activities. The other Activities are UI-oriented - two simply display weather data pulled from a website and the third to provide a location 'picker' so the user can choose which area to show the weather for.
However, all four activities make use of a WeatherHelper object which basically does everything from checking for available SD card storage to maintaining preferences and pulling/formatting website pages.
So, my question(s)...what is the best way to have one instance of WeatherHelper which can be used by multiple activities and where/how are best to create it in my case?
I've been an OO programmer for a lot of years but I'm very new to Android and the design concepts - I've read a lot on the Android Developers site over the past weeks but I've stalled trying to decide on this.
View 2 Replies
View Related
Jul 2, 2010
I have an Android application composed by several Activities. Most of them need to check whether an active network is available or not:
public boolean isNetworkAvailable() {
ConnectivityManager cm = (ConnectivityManager)
getSystemService(Context.CONNECTIVITY_SERVICE);
TelephonyManager tm = (TelephonyManager)
getSystemService(Context.TELEPHONY_SERVICE);
...
}
I would like to move that code to a helper class in order to avoid the need to write that code in every Activity, but calls to getSystemService are only allowed from an Activity. The other alternative is to move that code to a parent activity use inheritance but:
Every activity already extends from android.app.Activity
Some of my activities already extend from a common my.package.BaseActivity
(Activity <- BaseActivity <- XXXActivity)
What do you recommend in this case? Is there any other alternative?
View 1 Replies
View Related
Aug 23, 2010
I am working on a small android project where it is necessary to share some data amongst several activities and a service that runs in a separate process. I would just like to know what are my options in terms of sharing data? Application class? IPC? File-based? Broadcasts?
View 3 Replies
View Related
Jun 24, 2010
I'm in the middle of writing myself an app and have run into a problem concerning the use of the same SQLite database within multiple activities.
I have one activity that is used to input and store data and multiple activities that need to then read that data. Within the first activity, it has no problem inputting the data into the database, but when I go to have the other activity read the data, it tells me the database is empty. Obviously I'm doing something wrong in my handling of this shared database.
Right now, I have a DataHelper class that handles everything. In each activity, I create a DataHelper object which then calls the openOrCreateDatabase() method. I then close the database upon exiting the activity. Obviously this isn't the right way to do it.
So, my questions is, what is the correct way to set up an SQLite database in an Android application and then access it in multiple activities?
View 7 Replies
View Related
Jun 22, 2010
I have two activities that both contain an identical context menu built programmatically using menu.add(int, int, int, CharSequence). They both use onCreateContextMenu and onContextItemSelected.
The first Activity contains a ListView, when the user long presses on an item the context menu appears for that item. The second Activity (a detail screen for each item in Activity 1) contains a button, when the user presses the button the context menu appears.
I'd like to share the code that creates the context menu between these activities. The only thing these activities share is the context menu, so it seems like a bit of overkill to create a superclass (e.g., ActivityOne extends ContextMenuActivity) that defines onCreateContextMenu and onContextItemSelected methods.
Is there a better way of sharing these methods between activities?
View 2 Replies
View Related
Sep 15, 2010
I want to share streams of a socket connection between the activities of a tab view. In particular the tab activity creates the socket and gets the i/o streams,so i want that tabbed activities use these streams to retrieve informations without reconnect to the server each time i switch from a tab to another. I know i can use the application class to have a global state, but i don't know how.
View 4 Replies
View Related
Jul 22, 2009
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?
View 17 Replies
View Related
Jun 23, 2010
I'm sharing some variables accross activities by using a class like this :
CODE:..........
Then I'm using these variables anywhere across my multiple activites with ...if (Globals.hint2_stockview_valuation == false) {....}
Pretty basic and it was working fine untill ...
I introduced some webview stuff like this:
CODE:...........
And here's the News_Webview.class:
CODE:............
The problem now is that, when it "comes back" from this Activity, it looks like my Globals variables have disappeared ?
if (Globals.hint2_stockview_valuation == false) {
fires an error :
06-23 12:14:03.443:
ERROR/AndroidRuntime(2611): Caused by:
java.lang.NullPointerException
2 Questions then:
Should I use something else than this "Global" class to share variables across activities ? Is it just bad practice to do this ?? I know that I can use the preferences but I thought it was quicker to do it this way (no need to "read" the preferences everytime I start a new activity ...Should I "get back" my savedInstanceState in some way when my activity returns from the News_Webview.class ?
View 2 Replies
View Related
Oct 12, 2009
Can two or more Android Activities open an sqlite3 database for write?
I have two Activities that need to insert data into the same sqlite database. When the second Activity calls SQLiteOpenHelper.getWriteableDatabase() an IllegalStateException is thrown with the message "SQLiteDatabase created and never closed".
I've been able to avoid the Exception by making my database object a singleton but I'm thinking there must be a better way.
View 2 Replies
View Related
Jun 15, 2010
I have an application that have a Google map on Google Android 1.5 since we have been working on the application for a long time, we are not in stage of upgrading to the newest framework, so we are using 1.5. Now, I have map locations that are dynamically generated and drawn on the map at run-time to visualize some streams, Up to this point the application is working fine, Now my problem is that I am trying to filter the objects ( addresses) to visualize only the on-screen ones. I do NOT want to visualize the addresses that are off-screen. The way I am trying to do this is to check the screen-coordinates of each object (address) before visualizing it, then it the coordinates (x,y) more than (0,0) and less than (320, 460). I should visualize it. I am trying to use this approach, but it is not working for some reasons, I have tried many posts but could not understand why, there must be something missing somewhere that I am not aware of.
View 11 Replies
View Related
Sep 19, 2012
I have my Google account also setup on my wife's phone so we can share purchased apps. However, everything else is shared too. For example, even though I have sync for everything on my account turned off, my calendar still showed up on my wife's phone until I disabled it in the calendar app. Also, I can't remove my Google Talk account from her phone so my messages show up on her phone.
This is on a pair of stock Samsung Galaxy S3 phones.
View 2 Replies
View Related
Nov 26, 2009
I use webview to address the url link, but I want to know how to get the url's domain name? such as when I link to http://www.yahoo.com, then I can get the "yahoo" domain name, so how to do that?
View 3 Replies
View Related
Sep 27, 2010
I am working on a program that will connect to a time server (time- a.nist.gov), retrieve the timestamp, and place it in a text field.
However, when I create the socket, I get an UnknownHost Exception for time-a.nist.gov
1. put the <uses-permission android:name="android.permission.INTERNET" /> tag right before the </ manifest> tag. I did this, and the change is still there.
2. use the static InetAddress.getByName() function to convert to an IP address (this still throws the same exception)
When I pass the IP address (129.6.15.28) to the socket constructor, the program works fine. It only breaks when I use the actual domain name.
I have written this program in Java and it works perfectly fine.
View 2 Replies
View Related
Jun 30, 2010
how to call BarCodeScanner, and return the value to a field.so now, i have a toast that says "successful scan" and then i want to pass the result to a new activity. when i comment out my intent, everything works (minus the passing of data/switching of screen, obviously) but when i run my project as is, it FC's no errors reported by eclipse in code or xml. any insights?
View 2 Replies
View Related
Nov 7, 2010
The behavior of XMLHttpRequests in Android is very odd when doing cross domain requests. The browser should either fail with an error and not perform the request, or it should follow CORS (http:// www.w3.org/TR/access-control/) and start with an OPTIONS request to the remote domain. The Android browser (2.1 and 2.2) instead performs the request, which is received by the remote server (and this is the dangerous part both for data leaking and remote attacks), but the response is not set in the javascript (status of 0 and responseText null)
View 4 Replies
View Related
Jul 9, 2010
I have Nexus One (Froyo). After a lot of struggle I set up the Email App for MS Exchange. It works fine until I am in Company WiFi zone (company domain). Once I switch to another WiFi zone (@ Home), it stops working and throws an error something like 'no server connection'. Can somebody please help me out resolving this problem?
View 1 Replies
View Related
May 14, 2010
I know about the existince of CookieManager, but how do I remove cookies of a domain only?
View 1 Replies
View Related