Android :: Safely Pass Object References To New Activities?
Dec 8, 2009
I'm working on an application that requires non-serializable objects to be passed between Activities. The following page suggests using a HashMap of WeakReferences to accomplish this:
http://developer.android.com/guide/appendix/faq/framework.html
Is this solution safe? I know Activities are completely destroyed and recreated when the screen orientation changes. Couldn't those weakly referenced objects get GCed in the split second when the screen is rotated, since they wouldn't be referenced elsewhere at that point?
View 3 Replies
Nov 17, 2010
I have an Object that I need to be able to pass between Activites. It implements Parcelable and I've written all the code related to that. The problem is that one of the properties of the Object is a Drawable - and really needs to be. Unfortunately, Drawable is neither Parcelable or Serializable. I don't understand how to pass it. The reason for having the Drawable is that I need to cache an Image that I've downloaded from the internet at runtime. I don't want to cache the images on the filesystem, since this would potentially end up using up a lot of space over time. I'm putting the image into a Drawable so that I can easily put it into an ImageView.
View 2 Replies
View Related
Jun 25, 2010
I'm writing some stuff in java and i ran into some problems lately. cut short, i need to compare an object i created to another instance of this very class i instantiazed before with different data.
looks like this:
CODE:........
with a class a:
CODE:..........
The problem is, that i end up finding out that the values from newA are always equal to those from oldA. so i guess sth went wrong with passing the references of the objects in the last line of the loop...i thought java always passes references of objects unless an explicit copy() is called? if this does matter: this code is running on android - don't know if the dalvik vm messes aroung with this...
View 5 Replies
View Related
Aug 28, 2009
I have an activity which implements an OnItemClickListener.code...
However, I need to pass some objects from MyActivity1 to MyActivity2 --
I see there is an Intent.putExtra() for all the basic types, and I even see a Bundle which is a collection of basic types, but how can I pass a generic "Object" to MyActivity2 ?
View 3 Replies
View Related
Jun 25, 2009
Is it possible to pass an object to the intent so i can access that object in my new activity?
View 2 Replies
View Related
Oct 15, 2009
There is an activity which has an object. This activity(say A) starts another activity(say B). Can B use some object in A?
View 7 Replies
View Related
Apr 8, 2009
I have two class, class A and B, B include class A, like this..
View 2 Replies
View Related
Mar 17, 2010
In my activity , I create a Bitmap object, and I need to launch another activity,
How can I pass this Bitmap object from the sub-activity (the one which is going to be launched)?
View 1 Replies
View Related
Nov 15, 2010
I have read posts on passing arrays from and to activities, but I am confused as to how I would do it for my specific case.
I have an array of objects called DaysWeather (a DaysWeather[] array) where the objects have several String attributes as well as a bitmap attribute. I read somewhere that you have to make it serializable or parceable or something, but it seems messy at first glance.
Could someone lead me in the right direction?
Is there a simple way to do this?
View 1 Replies
View Related
Feb 12, 2010
Is it possible to pass a JavaScript object from JavaScript to Java using addJavascriptInterface()? Something along these lines: var javaScriptObject = {"field1":"string1", "field2":"string2"}; JavaScriptInterface.passObject(javaScriptObject); How would such a call be captured on the Java side? I have no problem setting up the interface to send a string, but when I send an object, I receive null on the Java end.
View 2 Replies
View Related
Sep 3, 2010
Can I pass a singleton class's object from one activity to another activity using intent? I am using singleton class as image class img = image class.get Instance();, so i need the img instance for another activity, how can i pass an object instance in Android.
View 2 Replies
View Related
May 12, 2010
I have this code fragment: Code...
View 3 Replies
View Related
Aug 7, 2009
I am developing an app that connects to a server. For that connection I created a class Client that maintains info about the connection . My app consists of several Activities and each of that Activity needs access to the Client object to communicate to the server. 1) Can I put somewhere the Client object so that all Acitvities have an access to it? 2) If not I would probably need to pass the object to each Activity via Intent.putExtra(). But putExtra doesn't accept Object as an argument. It only accepts several types like int, long, String etc. So how can I pass an object to another Activity?
View 2 Replies
View Related
Mar 26, 2010
I want to show messageBox or notification when connection lost in Static DB class but i cant use getApplicationContext() because its a static class and i tried to call other class called notification but i have error so how i could pass activity object to my new class .
View 3 Replies
View Related
Oct 3, 2010
I have a class A which is responsible for fetching data from web services in android and i have a class B which is responsible for creating and rendering List View in android
Now how can i populate data on List View once the data is fetched successfully.
well i have following options but which one is better .. (if someone has anyother then i don't mind)
1) Create an intent of Class B and
pass the data that need to be
populated
2) Creating a static method int Class
B which will accept the data as an
argument and call setListAdapter
in class B i have used Holder Patter to create ListActivity. ( for reference List14.java in samples of Android )
View 1 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
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
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
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
May 25, 2010
I need to be able to use one object in multiple activities within my app, and it needs to be the SAME object. What is the best way to do this?
I have tried making the object "public static" so it can be accessed by other activities but for some reason this just isn't cutting it. Are there any other ways of doing this?
View 6 Replies
View Related
Apr 19, 2010
I'm building an android application, which has a list view, and in the list view, a click listener, containing an onItemClick method. So I have something like this:
public class myList extends ListActivity {
@Override
public void onCreate(Bundle savedInstanceState) {
getListView().setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> parent, View view,
int position, long id) {
/* Do something*/
}
}
}
Normally, this works fine. However, many times I find myself needing too preform an application using the outer class as a context. thusfar, I've used: parent.getContext(); to do this, but I would like to know, is that a bad idea? I can't really call: because it's not really a subclass, just an embedded one. So is there any better way, or is that considered cosure? Also, if it is the right way, what should I do if the embedded method doesn't have a parameter to get the outside class?
View 2 Replies
View Related
Aug 21, 2009
I define a class Rect and a aidl file as below. code...
View 2 Replies
View Related
Jan 3, 2010
How can we pass checked box status from one activity to the calling activity? For e.g., I have two activities. The first activity calls the second activity that has a listview with checkboxed items and two buttons, 'OK' and 'CANCEL'. The second activity has to pass the names of list items that are checked to the calling acitivity. I am not able to figure out how to do this efficiently?
View 4 Replies
View Related
Apr 19, 2010
Today I met a problem, I need to pass a ArrayList<MyClass> from an activity to another. I dont know what the Intent exactly do when I use putExtra to pass in an ArrayList<MyClass> object. I guess MyClass need to implement Parcelable interface, so I just did it. But still, it does not work. Maybe I need to create a Bundle and then use Bundle's putParcelableArrayList method to put my ArrayList<MyClass> object in, and then pass this bundle as parameter of putExtra to the intent. So crazy! I am lazy, I just want to pass an ArrayList<MyClass> object simply, is there a simple way??
View 10 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
Apr 3, 2010
I currently have a service called ConnectionService. It instantiates a Connection object that gives me access to a controller of TCP.
I start the service from a splash screen activity, which sends and intent and starts my "main" activity once a connection has been established. In the "main" activity, I can access my Connection object and communicate with the controller. However, when I start a new activity from the "main" activity and bind to the service, I get a NullPointerException when I try to call methods in the ConnectionService.
View 11 Replies
View Related
May 13, 2010
I am developing an application using services and Remote interface. I have a question about passing the reference of my Remote interface throughout Activities. In my first Activity, I bind my service with my activity, in order to get a reference to my interface I use
private ServiceConnection mConnection = new ServiceConnection() {
@Override
public void onServiceConnected(ComponentName arg0, IBinder service) {
x = X.Stub.asInterface(service);
}
@Override
public void onServiceDisconnected(ComponentName arg0) {
// TODO Auto-generated method stub
}
};
x being the reference to my interface. Now I would like to access this interface from another activity, I see two ways to do it but I don't know which one is the "proper" way to do it: passing x with my intent when I call the new Activity redo this.bindService(new Intent(y.this,z.class), mConnection, Context.BIND_AUTO_CREATE); in the onCreate() of my new Activity
View 1 Replies
View Related
Jun 3, 2010
How to pass data between activities in an Android application?
View 1 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
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