简体   繁体   中英

Monodroid - Cant start new Activity/Intent

I am making an app using monodroid and i am trying to start a new activity.

Below is my code i am using to start the new activity

var second = new Intent(this, typeof(CreateVehicle));
        StartActivity(second);

and this is the Create Vehicle Activity

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using Android.App;
using Android.Content;
using Android.OS;
using Android.Runtime;
using Android.Views;
using Android.Widget;

namespace BoostITAndroid.Android
{
[Activity(Label = "My Activity")]
public class CreateVehicle : Activity
{
    protected override void OnCreate(Bundle bundle)
    {
        base.OnCreate(bundle);

        // Create your application here
    }
}
}

My problem is I cant run the application because in the intent CreateVehicle is under lined red and it says it doesnt exist.

add

<activity 
        android:name="YourPackageName.SecondActivityNameOnly"
        /> 

to you AndroidManifest.xml

it should look like this :

     <activity
     android:name="com.webview.MainActivity"
     android:label="@string/app_name" >
     <intent-filter>
        <action android:name="android.intent.action.MAIN" />

        <category android:name="android.intent.category.LAUNCHER" />
    </intent-filter>
    </activity>
    <activity 
    android:name="YourPackageName.SecondActivityNameOnly"
    />

我发现清单出现问题时,只需对项目进行简单清理就可以解决问题。

I see two possible issues: 1. The CreateVehicle activity is missing SetContentView method; 2. May be you have CreateVehicle activity in another namespace

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM