Difference using for Intent-methods

General topics about the Android-Platform itself.
Coding issues please to the subforum right below.

Difference using for Intent-methods

Postby sommeralex » Sat Jan 26, 2008 5:34 pm

Hello..

I have some problems with the doc and the code-examples. If i want to change from one activity to another, i use

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. Intent intent = new Intent();
  2.             intent.setClass(Forwarding.this, ForwardTarget.class);
  3.             startActivity(intent);
  4.             finish();
  5.  
  6.  
Parsed in 0.030 seconds, using GeSHi 1.0.8.4


ok. but the doc description (for eg. "chaining multiple calls into a single statement." is not so understandable for me:

public Intent setClass(Context packageContext, Class cls)
Convenience for calling setComponent(ComponentName) with the name returned by a Class object.
Parameters
packageContext A Context of the application package implementing this class.
cls The class name to set, equivalent to setClassName(context, cls.getName()).
Returns

* Returns the same Intent object, for chaining multiple calls into a single statement.

See Also

* setComponent(ComponentName)


any ideas what they mean?

thx, alex
sommeralex
Experienced Developer
Experienced Developer
 
Posts: 95
Joined: Sun Jan 20, 2008 3:12 am
Location: Vienna

Top

Postby plusminus » Sat Jan 26, 2008 7:02 pm

Hello sommeralex,

to busy to have a close look but changing to another Activity is done a bit different from yours. Just like that:
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.                     Intent i = new Intent(CurrentActivity.this, NextActivity.class);
  2.  
  3.                     // We use MY_SUB_ACTIVITY_REQUEST_CODE as an 'identifier'
  4.  
  5.                     startSubActivity(i, MY_SUB_ACTIVITY_REQUEST_CODE); // or just startActivity...
Parsed in 0.031 seconds, using GeSHi 1.0.8.4


Regards,
plusminus
Image
Image | Android Development Community / Tutorials
User avatar
plusminus
Site Admin
Site Admin
 
Posts: 2688
Joined: Wed Nov 14, 2007 8:37 pm
Location: Schriesheim, Germany

Postby sommeralex » Sat Jan 26, 2008 8:21 pm

i know! thank you - the code was from the android-example describing how to switch completly from one activity to another. i just dont understand: "chaining multiple calls into a single statement."
sommeralex
Experienced Developer
Experienced Developer
 
Posts: 95
Joined: Sun Jan 20, 2008 3:12 am
Location: Vienna

Postby plusminus » Sun Jan 27, 2008 12:33 pm

Hello sommeralex,

it means you can do strange things like this (sometimes even useful ;) ):
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. Intent i = new Intent();
  2.  
  3. i.setClass().otherFunction().funnyFunction().setClass().bla()....;
Parsed in 0.034 seconds, using GeSHi 1.0.8.4


Regards,
plusminus
Image
Image | Android Development Community / Tutorials
User avatar
plusminus
Site Admin
Site Admin
 
Posts: 2688
Joined: Wed Nov 14, 2007 8:37 pm
Location: Schriesheim, Germany

thx

Postby sommeralex » Sun Jan 27, 2008 3:26 pm

thx for your answer!

so, its e.g usefull for method invocations of foreign classes..
(?)
sommeralex
Experienced Developer
Experienced Developer
 
Posts: 95
Joined: Sun Jan 20, 2008 3:12 am
Location: Vienna

Postby plusminus » Sun Jan 27, 2008 3:36 pm

Hello sommeralex,

no, but there are several function you can "chain in one line":
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. Intent          addCategory(String category)
  2.  
  3.         Add a new category to the intent.
  4.  
  5.  
  6.  
  7. Intent          addLaunchFlags(int flags)
  8.  
  9.         Add additional launch flags to the intent (or with existing flags value).
  10.  
  11.  
  12.  
  13. Intent          setAction(String action)
  14.  
  15.         Set the general action to be performed.
  16.  
  17.  
  18.  
  19. Intent          setClass(Context packageContext, Class cls)
  20.  
  21.         Convenience for calling setComponent(ComponentName) with the name returned by a Class object.
  22.  
  23.  
  24.  
  25. Intent          setClassName(String packageName, String className)
  26.  
  27.         Convenience for calling setComponent(ComponentName) with an explicit application package name and class name.
  28.  
  29.  
  30.  
  31. Intent          setClassName(Context packageContext, String className)
  32.  
  33.         Convenience for calling setComponent(ComponentName) with an explicit class name.
  34.  
  35.  
  36.  
  37. Intent          setComponent(ComponentName component)
  38.  
  39.         (Usually optional) Explicitly set the component to handle the intent.
  40.  
  41.  
  42.  
  43. Intent          setData(ContentURI data)
  44.  
  45.         Set the data this intent is operating on.
  46.  
  47.  
  48.  
  49. Intent          setDataAndType(ContentURI data, String type)
  50.  
  51.         (Usually optional) Set the data for the intent along with an explicit MIME data type.
  52.  
  53.  
  54.  
  55. Intent          setLaunchFlags(int flags)
  56.  
  57.         Set special launch flags controlling how this intent is handled.
  58.  
  59.  
  60.  
  61. Intent          setType(String type)
  62.  
  63.         Set an explicit MIME data type.
Parsed in 0.040 seconds, using GeSHi 1.0.8.4


Regards,
plusminus
Image
Image | Android Development Community / Tutorials
User avatar
plusminus
Site Admin
Site Admin
 
Posts: 2688
Joined: Wed Nov 14, 2007 8:37 pm
Location: Schriesheim, Germany

Top

Postby sommeralex » Sun Jan 27, 2008 4:23 pm

thx again.. i guess the trouble is that i am still unsure about "intents" - what they are.. in detail..
sommeralex
Experienced Developer
Experienced Developer
 
Posts: 95
Joined: Sun Jan 20, 2008 3:12 am
Location: Vienna

Postby jaro » Mon Mar 24, 2008 7:06 pm

to call known activity / package just use:

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. Intent i = new Intent();
  2.  
  3. i.setComponent(
  4.  
  5.    new ComponentName("com.my_project.my_name"
  6.  
  7.                                 ,"com.my_project.my_name.Class_to_run"));
  8.  
  9. startActivity(i);
Parsed in 0.036 seconds, using GeSHi 1.0.8.4
jaro
Freshman
Freshman
 
Posts: 3
Joined: Mon Mar 24, 2008 6:53 pm

Top

Return to General

Who is online

Users browsing this forum: No registered users and 5 guests