2013-08-22 62 views
0

我使用MonoDroid的,我想开始具有我不想使用intent.putextra或任何束启动活动与参数

例如,这是我的活动性参数的新活动

namespace BoostITAndroid 
{ 
[Activity(Label = "My Activity")] 
public partial class UploadDealership : ListActivity 
{ 

    private List<Dealership> listDealers; 
    private Vehiclestoupload ul; 
    private int selectedDealershipID = 0; 
    private String[] Options; 

    public UploadDealership(Vehiclestoupload uploadList, List<Dealership> listOfDealers) 
    { 
     this.ul = uploadList; 
     this.listDealers = listOfDealers; 
    } 

所以这个活动有两个参数。

下面我试图启动活动

Intent uld = new Intent(this, typeof(UploadDealership(this, listOfDealers))); 
       StartActivity(uld); 

但是,一切都被红色下划线所以这行不通。

如何使用参数启动活动?

+0

你可以提供一个单用私有构造和公共'得到(上下文CTX)'这要么返回一个新的项目列表或当前项目已经创建。然后,您可以从任何活动或片段传递任何东西来访问它。 – ChiefTwoPencils

+0

你有没有例子? –

+0

也许您正在寻找使用首选项? http://stackoverflow.com/questions/13762032/shared-preferences-in-mono-android –

回答

0

也许这可能对您有用。这是在活动之间携带一个字符串。

在活动一:

 //Intent i = new Intent() 
    EditText editText = (EditText) findViewById(R.id.editText); 
    String message = editText.getText().toString(); 
    intent.putExtra(EXTRA_MESSAGE, message); 
    //StartActivity(i); 

在活动二:

// Get the Intent that started this activity and extract the string 
Intent intent = getIntent(); 
String message = intent.getStringExtra(MainActivity.EXTRA_MESSAGE); 

// Capture the layout's TextView and set the string as its text 
TextView textView = (TextView) findViewById(R.id.textView); 
textView.setText(message);