Intents?

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

Intents?

Postby chaoz1336 » Thu Jul 16, 2009 2:58 pm

Hi Guys,

I know what Intents are and what they are for..
and I( found some intent-examples..
but anyhow I think they dont work anymore in 1.5.

Can anyone give me a very SIMPLE example of "how to start an intent and get the result?" ...
(the Intent I want 2 start is a mini application of me ... )

greetz n thx
chaoz1336
Experienced Developer
Experienced Developer
 
Posts: 90
Joined: Wed Dec 10, 2008 5:19 pm

Top

Postby Erykgecko » Tue Jul 21, 2009 12:10 am

I think you;re talking intents to start a subactivity that passes a value back right? Theres a tutorial in the novice tutorials section, but it's changed slightly for 1.5

To call your subactivity and set it up for a result use something like

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.            
  2.  
  3. protected static final int SUB_ACTIVITY_REQUEST_CODE = 1337;
  4.  
  5. ....
  6.  
  7. Intent i = new Intent(mainactivity.this, subactivity.class);
  8.  
  9.            startActivityForResult(i, SUB_ACTIVITY_REQUEST_CODE);
  10.  
  11.            }
Parsed in 0.031 seconds, using GeSHi 1.0.8.4


To pass your result back from your subactivity use

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.        
  2.  
  3. protected final int SUCCESS_RETURN_CODE = 1;
  4.  
  5. ....
  6.  
  7. Intent data = new Intent();    
  8.  
  9. data.putExtra("stringname", "Hi, I'm a string!");  
  10.  
  11. subactivity.this.setResult(SUCCESS_RETURN_CODE, data);
  12.  
  13. subactivity.this.finish();
Parsed in 0.031 seconds, using GeSHi 1.0.8.4


Then, to make use of that returned data, you want

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.     protected void onActivityResult(int requestCode, int resultCode, Intent data) {
  2.  
  3.          super.onActivityResult(requestCode, resultCode, data);
  4.  
  5.          if(requestCode == SUB_ACTIVITY_REQUEST_CODE){
  6.  
  7. //Do Something Fun Here!
  8.  
  9. }
Parsed in 0.035 seconds, using GeSHi 1.0.8.4


Hope this makes sense, Took me ages to work it out a couple days ago
Erykgecko
Junior Developer
Junior Developer
 
Posts: 20
Joined: Sat May 16, 2009 5:32 pm

Top

Return to View, Layout & Resource Problems

Who is online

Users browsing this forum: No registered users and 4 guests