简体   繁体   中英

Using Intent in an Android application

In my Android application, I have two activity classes. I have a button on the first one and I want to show the second when it is clicked, but I get an error. Here are the classes:

public class SplashActivity extends Activity {
    Button b;

    @Override
    public void onCreate(Bundle bun) {
        // TODO Auto-generated method stub
        super.onCreate(bun);
        setContentView(R.layout.splash);

        b=(Button)findViewById(R.id.skipp);

        b.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View view) {
                // TODO Auto-generated method stub
                startActivity (new Intent(SplashActivity.this, MCActivity.class));
            }
        });
    }

    @Override
    protected void onPause() 
        {
        // TODO Auto-generated method stub

        finish();
    }


}

Second class:

public class MCActivity extends Activity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
    }
}

And i have added

<activity android:name=".MCActivity" />

in manifest too,within <application> tags...

Still have the run time error activity stopped unexpectedly when i click on button b..

Write Below onPause() Code

@Override
protected void onPause() {
    // TODO Auto-generated method stub
    super.onPause();
    finish();
}

instead of your onPause Code.

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