Android :: Pass Objects Around Activities Using A HashMap Of WeakReferences To Objects?

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.".................

Android :: pass objects around activities using A HashMap of WeakReferences to Objects?


Android :: Pass Data Between Activities - HashMap Of WeakReferences To Objects

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

Android :: Pass Objects Between Two Activities?

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

Android :: Pass Complex Objects Between Activities

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

Android :: Pass Socket - Inputstream - Outputstream Objects Between Activities

Jun 29, 2010

How to pass socket, inputstream, outputstream objects between activities

View 1 Replies View Related

Android :: How To Filter Objects To Display Onscreen Objects On Map?

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

Android :: Pass Objects From One Dialog To Other

Oct 27, 2010

I am trying to design an activity in Android which consist in a ListView with a button to add items to the List.

When the button is clicked, it opens a chain of Dialogs to configure the new item (each Dialog configures one attribute of the item Object). When the last Dialog is validated, the item is added to the list.

I was thinking of creating a new item Object when the first Dialog opens and using a setXXX() method on each Dialog validation to configure the object, but how am I supposed to pass the object from one Dialog to another?

I got it working using final objects, but it doesn't look clean to me at all. Plus I would have liked to use the activity Dialog manager methods such as onCreateDialog() and showDialog() to manage the Dialogs.

What is the cleanest way to do this?

View 1 Replies View Related

Android :: Pass Complex Objects With Help Of Intents?

Nov 18, 2010

I am trying to extend the "android.content.Intent" class by adding a private attribute of a custom class. My goal is to send complex objects from the main Activity to a background Service.
The extension itself is not a problem, the class gets compiled without any errors and the project runs. The only problem is that the BroadcastReceiver does not receive the modified Intent and the "onReceive" method gets never called.
It there any way to pass complex objects with the help of Intents?

View 1 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 :: 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

Android :: Singleton Objects To Save State Or Share Data Between Activities?

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

Android : How To Pass A Map (hashMap) From Javascript To Droid?

Jun 29, 2009

I'm trying to pass a map from javascript to a java function which has to get that map information and process it.

View 3 Replies View Related

Android :: How To Manage Objects ?

Sep 8, 2010

I am new to Android development. I want to know how you all manage objects. For eg we make object as A a = new A(); and then manage that object. But, here, we call A.class; My concern is that i don't want to call on Create(),nor do i want to push UI screen I just want to make 1 static object for 1 screen;and want to manage it throughout my application. that is, instead of calling A.class; can i call A a = new A(),and manage that object without pushing,and whenever i need i push that screen. Is there someway?

View 1 Replies View Related

Android :: Passing An ArrayList Of Objects

Nov 12, 2010

Is there a way to pass an Array List of objects between activities? The myObject implements Parcelable and I'm able to successfully pass the objects around individually, but that means I need to have an exact amount of "myObjects" coded. I want this to dynamically grow/shrink by what the user does with the app. I have seen some posts on the web about doing:

Activity A
ArrayList<myObject> myObjArray = new ArrayList<myObject>();

Then when passing this into the intent I would use:
intent.putParcelableArrayListExtra("myObjArray", myObjArray);

Activity B
ArrayList<myObject> myObjArray = new ArrayList<myObject>();
Bundle extras = getIntent().getExtras(); myObjArray = extras.getParcelableArray("myObjArray");

However, the myObjArray always gets filled with "null". How can I achieve this?

View 3 Replies View Related

Android :: Persistance Of Dynamic Objects

Aug 7, 2009

I am new to this android stuff and SQLlite etc.I am going to log some numbers at a certain interval, and will put them into a dynamic histogram, by dynamic i mean that there will be a maximum number of samples in the histogram, the histogram and age stuff should be persisted either in db or plain file.For simplicity, I would like the samples to be stored in a blob type datafield, but i cannot se if this is possible. Alternative i could have another table with the samples Or I could simply have files with filename = name and content = samples.my concern might be unclear by now, but put simply, what is most effecient regarding power usage?

View 3 Replies View Related

Android :: Storing An Array Of Objects

Mar 31, 2010

I have an array of 5 Timer objects in my app, some of wich have been scheduled with a TimerTask. I need to be able to store and load these 5 Timers; is there a way to save Objects? Maybe storing the address of the array would be enough? How could I do that?

View 8 Replies View Related

Android :: How To Draw 3D Objects On A MapView?

Oct 20, 2009

I have been able to draw a map using 'MapActivity' class. Am unable to render 3D graphics on the Map. Is there any way to draw something on the foreground with the Map as the background?

View 2 Replies View Related

Android :: Getting Current On Screen GUI Objects

Mar 19, 2009

Is there any way for an Android application to retrieve some sort of Collection object that contains references to all of the GUI elements which are currently on the phone's screen? This could be very useful for testing purposes and so on. If I have overlooked a well-known class or library, please let me know.

View 3 Replies View Related

Android :: How To Add Objects To Sqlite Database?

Nov 18, 2009

I have a class like class My data{ String name; int data; Location[] locality.

View 8 Replies View Related

Android :: How 3D Objects Get Touch Events?

May 31, 2009

I am writing a game using OPENGL, there are several 3D objects in my surface view. My question is: Should each 3D object implement view in order to get touch events? Or there is other way to do this?

View 5 Replies View Related

Android :: Writing Objects From Thread

Jul 22, 2010

I have a game object that I save like this in OnPause()try {final ObjectOutputStream os = new ObjectOutputStream(openFileOutput(gameName + ".sav", 0)); os.writeObject(gameObject); os.reset();} catch (final Exception e) {e.printStackTrace();This works fine except on some of the older or slower phones it can sometimes take too long to complete. I end up getting a ANR (Activity Not Responding) error. I would like to move this to a thread to prevent blocking the UI. However when I try this I run into multiple problems.First openFileOutput is only available in my activity. I worked around this by passing the ObjectOutputStream to the thread. After that I could save the object but later when I tried to reload I get a java.io.EOF Exeception. does anyone have a good pattern for writing objects to a file from a thread?

View 1 Replies View Related

Android :: How To Send Objects Through Bundle?

Nov 22, 2010

I need to pass a reference to the class that does the majority of my processing through a bundle. The problem is it has nothing to do with intents or contexts and has a large amount of non-primitive objects. How do I package the class into a parcelable/serializable and pass it to a startActivityForResult?

View 4 Replies View Related

Android :: Correct Way To Add Objects To An ArrayList

Aug 19, 2010

I am trying to add an object to an arraylist but when I view the results of the array list, it keeps adding the same object over and over to the arraylist. I was wondering what the correct way to implement this would be.

CODE:..............

I have double checked my JSONArray data and made sure they are not duplicates. It seems to keep adding the first object over and over.

View 2 Replies View Related

Android :: Eclipse MAT Does Not Appear To Show All App's Objects / How To See It

Feb 4, 2010

I have created an hprof file by inserting the statement Debug.dumpHprofData("/sdcard/myapp.hprof"); in my app's code; I have then run the hprof file through hprof-conv and opened the converted file in Eclipse.

Following the advice of the MAT "Cheat Sheet" I have obtained an analysis of my app's memory usage by going to "Leak Identification -> Component Report" entering "com.prepbgg.*" and hitting Finish.

I know that my app is consuming large amounts of memory: in particular at the stage where I called dumpHprofData it had a one megapixel bitmap object and a canvas that must have consumes several hundred KB. (I also suspect that it is leaking significant amounts of memory because performance degrades severely after the screen has been rotated a few times.)

However, the Component Report for com.prepbgg.* shows total memory of only 38.7KB. The Histogram view shows for android.graphics.Bitmap (presumably this is the total of all apps including mine) 404 objects and Shallow Heap 12,928. Is that 12,928 bytes?

Clearly, my app consumes more than 38.7KB and the Bitmap far more than 12,928 bytes. Where am I going wrong? How can I see the total memory consumed by my app?

View 1 Replies View Related

Android :: Bundles And Serializable Objects - What Is Actually Stored?

Mar 24, 2009

was wondering about the behavior of Bundles and serializable objects. If I put a serializable object into a bundle, what is serialized then, the reference to the object or the object itself? I always assumed that the object itself would be serialized to a byte stream when calling putExtra() and re-created from that representation when calling getSerializableExtra(), but I recently stumbled upon a piece of code that put an entire view into a Bundle in thread A, retrieved it from that bundle in thread B, performed a modification on it and this modification actually became visible. This can only happen if the reference to that view was stored, not the view itself, right? Otherwise, the modification had been applied to a copy of that view and would be meaningless.

View 3 Replies View Related

Android :: Unmarshalling XML Files Into Java Objects

Aug 29, 2009

I'm making use of an API on the internet that is marshalling objects to XML files. Given that the XSD files are also available I'd like to be able to unmarshall them back in to Java objects once I've downloaded the files.After looking around it looks like JAXB is the default library for doing this in Java, but as I'm developing a mobile app the extra 8.6MB dependency just isn't acceptable. I also found XStream, but it still weighs in at 7.9MB.Poking around the Android SDK it looks like the only real XML parser available is SAX.

View 6 Replies View Related

Android :: How To Drag Marker Objects In A MapView?

Jun 4, 2009

Hey Is it easy/possible to drag marker objects in a MapView?

View 10 Replies View Related

Android :: Download Multiple Objects From Same Server

May 5, 2010

How can I utilize Connection: Keep-Alive option, re-use connection and download multiple objects from the same server? HTTP connection consists of opening a socket, sending request and then readign response. For Keep-Alive option open the socket connection needs to be done only once. However I could not find in Android Java classes how this can be accomplished. URL.openConnection returns new instance of HttpURLConnection implementation for every request so HttpURLConnection cannot be cashed for reusing on multiple requests to the same server, URL object is also new for each request and also cannot be reused.

View 2 Replies View Related

Android :: Parse Data - Multiple Objects

Oct 29, 2010

i need to parse this response in android using the android json parser but the thing i cant find the answer to anywhere is: how do i parse the data if for example "itineraries" can contain one or sometimes more objects of the type itinerary? if it contains one than it is returned like this but if it contains more it is returned with [] with this example "itinerary" cannot be placed into a JsonArray becouse obviously it is not an array. (not placed in [] right?)

how do i parse this? any examples?
{
"plan":{
"date":"2010-10-20T00:00:00+02:00",
"from":{
"name":"Булевар Партизански Одреди",................

View 1 Replies View Related

Android :: Need To Bypass Constructors When Instantiating Objects

Jun 25, 2010

Do Android have any way to instantiate objects without calling any of its constructors? In Java, Sun have sun.reflect.ReflectionFactory.getReflectionFactory().newConstructorForSerialization(), in .Net we have System.Runtime.Serialization.FormatterServices.GetUninitializedObject() but I was not able to find anything like that in the Android platform.

View 3 Replies View Related







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