Android :: Sharing Data Between Activities / Activity2 A Pointer To Object1

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?

Android :: Sharing data between activities / Activity2 a pointer to Object1


Android :: Sharing Data Between Activities

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

Android :: Sharing Data Between Tab Activities

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

Android :: Sharing Data Across Activities

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

Android :: Sharing Data Amongst Activities And Services

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

Android :: Sharing Code Between Activities

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

Android :: Sharing Cursor Between Activities

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

Android :: Sharing An Object Between Activities

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

Android :: Several Activities Sharing Common Code

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

Android :: Sharing SQLite Database Between Activities

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

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 View Related

Android :: Sharing A Context Menu Between Activities

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

Android :: Sharing Stream Object Between Activities Of Tab View

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

Android :: Sharing Global Variables Across Activities - Problem When Using Webview

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

Android :: Switching Activities / Passing Data Between Activities

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

Android :: Sharing Sqlite Database Between Multiple Android Activities

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

Android :: Returning Data From AsyncTask Resulting In Null Pointer Error

Jul 20, 2010

I am trying to do what I think is a fairly simple task to authenticate a user on my server. I am using AsyncTask as a private subclass of my Activity, however when I try to populate the user object after authenticating it keeps setting it to null. Is there something strange in how the onPostExecute() method is called that is causing this? I originally had the AsyncTask as its own class but ran into the same problem, so I am try to solve this using a private subclass.

View 2 Replies View Related

Android :: Null Pointer Exception Occurs When Trying To Create File And Write Data

Oct 26, 2010

I am trying to create a file ,if it doesnot exist and tried to write some data to it. The same program I did in java, it was running fine.But when I try to do the same thing in Android I am getting NullPointerException at the place where I am trying to write data to file. And also, I did not find any new file in the current directory .

View 2 Replies View Related

Android :: Sharing Data Between Users

Aug 25, 2010

I'm writing a game that includes an editor for users to create their own levels. I'd like players to be able to share the levels they've created with other players. I'm trying to figure out the best way of implementing that, and hoping for any advice on the subject.

One obvious option is to set up a server for sharing levels. The game would connect directly to the server to let players share their creations or download levels created by other players. This provides seamless integration and a good user experience, but I'd really prefer not to use this approach. For one thing, I don't want the cost and responsibility of setting up and maintaining the server. And I would be taking on a basically unlimited obligation; otherwise, if I decided to shut down the server a few years from now, the game would suddenly lose a large part of its value.

Another idea I had is to use the Android Market as the way to distribute sets of levels. That way, Google is taking care of running the server for me. Clearly there are programs that work this way, since I've seen lots of themes and expansion packs for particular applications in the Market. While this could work, I'm not very happy with it. Asking an ordinary user to sign up for a developer account on the Market and learn how to post files through it is unreasonable, not to mention they would have to pay $25.

The approach I'm currently leaning toward is allowing levels to be exported as ordinary files. People could then just email them to each other, post them on any website they wanted, etc. Ideally I would want to set up a file type association so they could simply open an email attachment or click a link in the web browser, and my game would automatically be launched to import it. I haven't yet looked into whether that's possible.

View 3 Replies View Related

Android :: Sharing Data Between Tabs

Jul 21, 2010

I am getting some glitches while making a tab enabled application.

I want to share data, between two tabs of mine application.

How can i achieve the same.

View 3 Replies View Related

Android :: Sharing Data On Two Apps

Oct 20, 2010

I am new in android development. i was wondering if i could share some data between two applications in android. One way is to place the text file on SD Card but i dont want to do this.Second way is to place in data folder, and i dont know how to.3rd way is to place the data in shared memory so both applications can see it.also i dont want the user to see or delete this file,only my two applications can change this file or data.Please help me.I've been wondering on this for 2 days.

View 5 Replies View Related

Android :: Sharing Data Between An Service And An Application

Jun 28, 2009

In order to share data between one of my own Android service and an application i am looking for the best way to do this. I have seen the shared memory drivers inside the GNU Linux kernel, but no Java api. Maybe the specific Google IPC Blinder cad be used for my need ?

View 10 Replies View Related

Android :: Google Apps Found To Be Sharing Data

Sep 30, 2010

BBC News - Google Android apps found to be sharing data

Quote:

View 26 Replies View Related

Android :: Options For Sharing App Data On Multiple Phones

Aug 22, 2010

I'm looking for suggestions for ways to share Android app data between phones running the same app. For example, lets say I have an app that stores a database of book reviews. If person A has a book review that person B doesn't have, what are the options for getting that information from person A's phone to person B's phone?

Currently, I'm aware of the following options:

- Upload data from person A's phone to a server, then download data from server to Person B's phone.
- Write code to have the phones sync up using bluetooth
- Write code to send SMS messages


I'm wondering if there are any more options besides these, and if there's actually a best-practice for accomplishing this?

Ideally, I want the users to simply click a button in the app to make the sharing take place, so I don't want to go down the bluetooth route because that requires the user to do a bit of setup (or assumes they already have set things up in the form of bluetooth settings).

Since the data can be of variable length and potentially large, I believe that would rule out text messaging.

As far as the server route goes, from what I understand this seems to be an ok way of doing things, but my problem is that I have no experience with having users potentially sign in to a server and then uploading data. I don't know of the cost concerns (if any), or of potential security concerns (allowing just anyone to upload data, I'm not sure if I would have to take steps to ensure someone couldn't bypass the app and upload malicious data).

View 3 Replies View Related

HTC EVO 4G :: Sharing Wifi Data

Jun 5, 2010

Has anyone tried sharing a wifi connection through the evo? I have a really old laptop without a wireless card and would like to be able to pick up wifi signal from my router with evo and use usb to share with my pc. Haven't tried yet and will when i get home bit just wondering if anyone had tried this or knows if it'll work.

View 3 Replies View Related

Android :: Data Between Activities

Jun 30, 2009

Is it possible to transfer data between activities without using "extars"? I need to access MyOwnObject in Atctivity 1 from Activity2 Possible with using static fields?

View 6 Replies View Related

Android :: Pass The Data To Sub Activities?

Jul 2, 2009

The main activity includes some variables with set values. I created a sub-activity with the form which has to be filled with the data from main activity so I guess the data have to be passed to the sub-activity when it starts. how to pass the variable values to the sub-activity from the main activity?

View 1 Replies View Related

Android :: Pass Data Between Activities?

Oct 6, 2010

I'm developing an app which basically navigates through a xml-feed. When I parse the feed or let's say the list, then each (list)item becomes a model. All the models are wrapped up in an array list. Now, when the user clicks on a list item, the underlying model is going to be serialized and sent as IntentExtra to the next Activity (e.g. a deeper sub list). (Originally I asked here a different question. The solution was not related to Serializable and wouldn't help anybody. However MatteKarla gave an interesting input. Thats why I decided to rewrite this question.)

View 1 Replies View Related

Android :: Send Data Between Activities Within My App?

Mar 9, 2010

I have a TabActivity, and the tabs point to sub activities. Is there a way I can send a 'message' to those child activities? I just want to pass a string across, not sure if this is possible.

I have some data being fetched by the parent TabActivity, and the child tabs can't do anything useful until the parent is done fetching. When fetching is complete, I'd like to pass that data to the child activities so they can do something useful with it.

Normally I'd set the data to be passed in the Intent when first creating the activity, but in this case I can't do that.

View 2 Replies View Related

Android :: Exchange Data (objects) Between Different Droid Activities?

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







Copyrights 2005-15 www.BigResource.com, All rights reserved