VaporIntent plays the same role in the Vapor Android framework as a standard
Intent does in Android.
Creating A VaporIntent
VaporIntent has two constructors, one of which takes your existing Android
Intent and encapsulates it. All of the existing data stored within the
Intent is preserved, and thereafter available via the
Intent myAndroidIntent; ... $.Intent(myAndroidIntent); // encapsulate an existing Intent
Secondly, you can instantiate a
VaporIntent using a
Context and the
representing the specific component for which you are creating the intent. This is particularly useful when are you do not have an existing
Intent object already.
$.Intent(activity, serviceClass); // using a Context and Class
This means you can chain calls like in jQuery, and use
.put(...) methods without having to worry about the actual datatype
of the item that you are committing to the intent.
$.Intent(activity, serviceClass) .put("someExtra", 25) .put("anotherExtra", "this is so easy!");
VaporIntents are used predominantly in conjunction with existing standard Android framework APIs that expect to be given
VaporIntents do not currently support storage of arbitrary reference types because these would be lost when the
VaporIntentwas converted to a standard Android
Developers should use the appropriate
.get____(String) method depending on the datatype being retrieved:
// Retrieve an Integer Integer integer = vaporIntent.getInt("someKey"); // Retrieve array of Doubles Double doubles = vaporIntent.getDoubles("someOtherKey"); // Retrieve list of Strings ArrayList<String> strings = vaporIntent.getStringList("anotherKey");
All of the public methods found in standard Android
Intents are available on
VaporIntents as fluent methods,
VaporIntent does not extend from
Despite this, you can easily extract the underlying
Intent object using
.intent() for compatibility with standard Android framework APIs.
VIntent<Intent> vaporIntent = $.Intent(activity, serviceClass); ... // compatibility with existing Android framework APIs Intent androidIntent = vaporIntent.intent();
See the docs on
VaporIntent for more details...