BlackBerry - how to pass data like Intent.putExtra() in Android -


i newbie on blackberry. how achieve (in blackberry) same of android's

intent.putextra("key","value"); 

to put values can received on next pushed screen in blackberry.

like in android activityone -

intent intent = new intent(this, activitytwo.class); intent.putextra("value1", "this value 1 activitytwo "); intent.putextra("value2", "this value 2 activitytwo"); startactivity(intent); 

in activitytwo -

bundle extras = getintent().getextras(); if (extras == null) { return; } // data via key string value1 = extras.getstring(intent.extra_text); if (value1 != null) { // data } 

is such thing possible in blackberry? if yes how do this?

using public static variables (as in ganesh's answer) work, in general, that's not object-oriented pattern recommend.

luckily, can easier in blackberry in android. android's intent mechanism unnatural many java developers. when 1 activity starts activity via intent, not new (create) instance of second activity, , doesn't hold normal java reference object. if did, problem simpler. android's implementation forces use intent extras mechanism.

if old activityone class becomes screenone blackberry, , activitytwo becomes screentwo, can this:

public class screentwo extends screen { private string _value1; // doesn't have string ... it's whatever want private string _value2; public void setvalue1(string value) { _value1 = value; } public void setvalue2(string value) { _value2 = value; } } 

then, in screenone, can start screentwo way

screentwo nextscreen = new screentwo(); nextscreen.setvalue1("this value 1 activitytwo"); nextscreen.setvalue2("this value 2 activitytwo"); uiapplication.getuiapplication().pushscreen(nextscreen); 

that's more consistent way java objects used, , interact 1 another.

there's reasons why android made intents , extras, in blackberry, don't have worry that.


edit: i'm trying consider think motivation behind mr. smith's comment below. if android intent extras mechanism in sense can pass multiple data types 1 activity another, key-value pairs, can achieve similar in blackberry. instead of screentwo code above, use this:

public class screentwo extends screen { private hashtable _extras; public void putextras(hashtable extras) { _extras = extras; } } 

where put(object, object) key-value pair data hashtable passed called screen, , read when need it. or even:

public class screentwo extends screen { private hashtable _extras; public void putextra(string name, object value) { _extras.put(name, value); } } 

Comments

Popular posts from this blog

javascript - backbone.js Collection.add() doesn't `construct` (`initialize`) an object -

php - Get uncommon values from two or more arrays -

Adding duplicate array rows in Php -