无法看到新的 activity

Unable to see new activity

我的意思是制作一个带有 "settings" 按钮的应用程序,按下时会创建一个新的 activity。我希望新 activity 显示实际设置页面。

这是“设置”按钮的 XML 代码:

<Button
android:text="Settings"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/buttonResSettings" />

这是我调用新 activity 的代码,它位于我的主 activity 的 OnCreate:

Button resSetButton = FindViewById<Button>(Resource.Id.buttonResSettings);
resSetButton.Click += delegate {
var ResSetAct = new Intent(this, typeof(ResSettingsActivity));
ResSetAct.PutExtra("res", res);
StartActivity(ResSetAct);
};

这是我的新代码 activity:

public class ResSettingsActivity : Activity
{
    protected override void OnCreate(Bundle bundle)
    {
        base.OnCreate(bundle);

        // Set the view to ResSettings(.axml)
        SetContentView(Resource.Layout.ResSettings);

        //Fetch the data of the variables
        string res = Intent.GetStringExtra("res");

        //Map the elements of the view to usable objects
        EditText CurRes = FindViewById<EditText>(Resource.Id.editCurRes);

        //Display the current values of the settings
        CurRes.Text = res;
    }
}

在模拟器中构建和使用应用程序的其余部分没有问题,但是当我单击该“设置”按钮时,没有任何反应(默认的 onClick 按钮设计更改除外)。

Intent theintent = new Intent(A.this,B.java);
theintent.putExtra("name",john);
startActivity(theintent);

同时在清单文件中声明 class b.java

您需要记得将 [Activity] 属性添加到您的新 Activity class:

[Activity(Label = "Res Settings")]
public class ResSettingsActivity : Activity 
{
    ...
}

该属性将在构建时为您在 AndroidManifest.xml 中添加一个条目。您可以通过查看 obj/Debug/android 文件夹来验证这一点,您可以在其中看到生成的清单。您应该看到如下条目:

<activity android:label="Res Settings" android:name="md51237869127761dfsa77sadvfb.ResSettingsActivity" />

如果您不希望名称以 md5 和作为前缀,您可以将 Name 属性 添加到 Activity 属性:

[Activity(Label = "Res Settings", Name = "my.package.name.ResSettingsActivity")]
Intent i = new Intent(getApplicationContext(), ActivityTwo.class);  

// Set the request code to any code you like, you can identify the  
// callback via this code  
startActivity(i);
    Intent intent = new Intent(this, DisplayMessageActivity.class);
    intent.putExtra(EXTRA_MESSAGE, message);
    startActivity(intent);

您可以传递这样的意图并在清单文件中声明 class DisplayMessageActivity