Why Button click redirection for another xml page

2019-06-01 01:58发布

I looked in to everything before ask this. I am implementing an application and new to android, I need to redirect to my mapview xml when login button click. So i have written the intent plus made the activity in manifest file and tried writing codes every possible different way. And the code doesn't give any errors. But my emulator stops after launching. I know something is wrong but I can't figure it out. Any idea why that happens?

here is my code

public class MainActivity extends Activity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        final Button button=(Button)findViewById(R.id.loginbtn);
        button.setOnClickListener(new View.OnClickListener() 
        {

            @Override
            public void onClick(View v) 
            {

                switch (v.getId()) {
                case R.id.loginbtn:
                    Intent intent = new Intent (MainActivity.this, MapView.class);
                    startActivity (intent);
                    break;
                default:
                    break;}
                }
             }
          );
        }
     }
                /*if(username.getText().toString()==""&&password.getText().toString()=="")
                {

                     Intent i= new Intent("com.example.shaz.MAPVIEW");
                     startActivity(i);
                }
                else
                {
                    txt.setText("False");


                }
            */  

Manifest

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.myname"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk
        android:minSdkVersion="17"
        android:targetSdkVersion="17" />

    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <activity
            android:name="com.example.myname.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=".mapView"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="com.example.myname.MAPVIEW" />

                <category android:name="android.intent.category.DEFUALT" />
            </intent-filter>
        </activity>


    </application>

</manifest>

I have also created an xml file for map called map_view in my layouts.

So in every where I searched this is how they say new intent is creating .

And the emulator works fine if I do something else than this redirection. SO what ever problem I got is within this redirection part.

2条回答
forever°为你锁心
2楼-- · 2019-06-01 02:19

Change:

 <category android:name="android.intent.category.DEFUALT" />

for this:

 <category android:name="android.intent.category.DEFAULT" />
查看更多
爷、活的狠高调
3楼-- · 2019-06-01 02:32

DEFAULT is spelled incorrectly in your Manifest

查看更多
登录 后发表回答