• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Opening a new activity crashes my app

This method of opening a new activity was working when I had my target android version as 25 and was running my app on the android emulator.

I have since given up trying to run my app on the emulator because it has become impossibly slow.

Instead I am building a signed APK and installing the app on my real mobile phone.

I downgraded the target SDK of my app to 10 because my mobile phone is quite old.

Now when I press one of the button in my main activity (which are supposed to start a new activity) the app crashes and I have the faintest idea why.

I have googled this problem and none of the suggested fixes work.

I commented out all the code in the onCreate() function of the class associated with my new activity, but it makes no difference - the app still crashes. So the problem has nothing to do with any code in my activity classes.

Suggestions?

Code:
package com.example.greg.irrigationcontroller;

import android.app.AlertDialog;
import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;

public class MainActivity extends AppCompatActivity implements View.OnClickListener
{

    // Used to load the 'native-lib' library on application startup.
    static {
        System.loadLibrary("native-lib");
    }

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

        m_buttonSettings = (Button)findViewById(R.id.id_button_settings);
        m_buttonSettings.setOnClickListener(MainActivity.this);

        m_buttonView = (Button)findViewById(R.id.id_button_view);
        m_buttonView.setOnClickListener(MainActivity.this);

        m_buttonSearch = (Button)findViewById(R.id.id_button_search);
        m_buttonSearch.setOnClickListener(MainActivity.this);

        m_buttonManual = (Button)findViewById(R.id.id_button_manual);
        m_buttonManual.setOnClickListener(MainActivity.this);
    }

    @Override
    public void onClick(View view)
    {
        Intent intent = null;

        switch (view.getId())
        {
            case R.id.id_button_settings:
                intent = new Intent(getApplicationContext(), SettingsStep1Activity.class);
                break;
            case R.id.id_button_search:
                break;
            case R.id.id_button_view:
                intent = new Intent(getApplicationContext(), ViewSettingsActivity.class);
            case R.id.id_button_manual:
                break;
        }
        if (intent != null)
            startActivity(intent);
    }

    protected Button m_buttonSettings, m_buttonView, m_buttonSearch, m_buttonManual;

}
 
Back
Top Bottom