State and Activity

Put problem concerning Views, Layouts and other XML-Resources (like AndroidManifest) here.

State and Activity

Postby mobilekid » Tue Nov 04, 2008 1:06 am

Hi,

I am still trying to get my head around some fundamental concepts in android.

I'd like to find out how to pass state from one activity to another. A perfect example is a login form.

Once the login has been performed, I could simply call:

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.  
  2. Intent i= new Intent(LoginActivity.this, MainActivity.class);
  3.  
  4. startActivity(i);
  5.  
  6. finish();
  7.  
  8.  
Parsed in 0.031 seconds, using GeSHi 1.0.8.4


However, if I want to pass on some state from the original activity, to manipulate it on the following, how do we go about that?

Thanks in advance!
mobilekid
Freshman
Freshman
 
Posts: 7
Joined: Mon Aug 04, 2008 10:34 pm

Top

Postby Quetzalcoatl » Tue Nov 04, 2008 1:17 am

This webby may be of some use, I just used the public static field to give me access to the other activity (not tried anything else yet).

Android IPC
Image
Quetzalcoatl
Senior Developer
Senior Developer
 
Posts: 129
Joined: Sat Oct 18, 2008 8:21 pm
Location: near Manchester, UK

Postby mobilekid » Tue Nov 04, 2008 8:49 am

Thank you for the link, Quetzalcoatl! Following the tips there the HashMap solution seems to be what I need.

http://code.google.com/android/kb/framework.html wrote: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 IPC


Has anyone used that solution?
mobilekid
Freshman
Freshman
 
Posts: 7
Joined: Mon Aug 04, 2008 10:34 pm

Top

Return to View, Layout & Resource Problems

Who is online

Users browsing this forum: No registered users and 7 guests