从活动到导航抽屉的意图问题

时间:2017-01-05 10:41:11

标签: java android android-intent navigation-drawer android-navigation-drawer

的Manifest.xml

using (var context = new Context())
    {
        // getting entity from db, reflect it to dto
        var countryDTO = context.Countries.FirstOrDefault(x => x.Id == 1).ToDTO<CountryData>();

        // add new city to dto 
        countryDTO.Cities.Add(new CityData 
                                  { 
                                      CountryId = countryDTO.Id, 
                                      Name = "new city", 
                                      Population = 100000 
                                  });

        // change existing city name
        countryDTO.Cities.FirstOrDefault(x => x.Id == 4).Name = "another name";

        // retrieving original entity from db
        var country = context.Countries.FirstOrDefault(x => x.Id == 1);

        // mapping 
        AutoMapper.Mapper.Map(countryDTO, country);

        // save and expecting ef to recognize changes
        context.SaveChanges();
    }

registration.java

 <?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="associate.aclass.associate1">
    <uses-permission android:name="android.permission.INTERNET"/>
    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:supportsRtl="true"
        android:theme="@style/AppTheme">
        <activity
            android:name=".registration"
            android:label="@string/app_name"
            android:theme="@style/AppTheme.NoActionBar">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
     <activity android:name=".MainActivity"> </activity>
    </application>

</manifest>

在我的MainActivity.java中     android studio提供导航抽屉模板

问题是: 当我打算从注册到其他活动,如abc.class。它工作正常,但当我打算从注册到包含导航抽屉的MainActivity.class。单击注册后,我的应用程序崩溃了。注册过程完成然后我的应用程序崩溃。它应该显示导航抽屉

而不是崩溃

1 个答案:

答案 0 :(得分:1)

如果您在主要活动中使用工具栏并将其设置为获取操作栏属性。因此,在您的宣言中添加一行

<activity android:name=".MainActivity"
          android:theme="@style/AppTheme.NoActionBar"> </activity>

我希望它能解决你的问题。