1. Are you ready for the Galaxy S20? Here is everything we know so far!

Strange issue going to new activity of click event

Discussion in 'Android Development' started by Atkinson_88, Dec 4, 2013.

  1. Atkinson_88

    Atkinson_88 Newbie
    Thread Starter

    Hello,

    I have created a new layout called settings.xml, created a new java class called settings.java

    Added the activity to the manifest as follows (Located at the bottom)

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

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

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

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

    <activity
    android:name="com.example.newapplication.settings"
    android:label="@string/app_name" >
    <intent-filter>
    <action android:name="android.intent.action.SETTINGS" />

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


    </application>

    </manifest>

    [/HIGH]

    My settings.xml is located res/layout
    the button im clicking is located in another activity which is called main
    this main activity has 4 buttons in total so im using a case statement to determine what button is pressed. when i click btnSettings i want to direct the user to the new activity

    [HIGH]
    case R.id.btnSettings:

    Intent MenuIntent = new Intent("com.example.newapplication.SETTINGS");
    startActivity(MenuIntent);



    break;
    [/HIGH]

    but instead my app says "Fatal error app is closing"

    and this is what i find in the stack trace/error
    [HIGH]
    12-04 14:07:20.536: E/AndroidRuntime(1089): android.content.ActivityNotFoundException: No Activity found to handle Intent { act=com.example.newapplication.SETTINGS }

    [/HIGH]


    this is my settings.java i have the oncreate method plus additional methods.

    [HIGH]
    protected void onCreate(Bundle savedInstanceState) {
    // TODO Auto-generated method stub
    super.onCreate(savedInstanceState);
    setContentView(R.layout.settings);

    cb = (CheckBox) findViewById(R.id.checkBox1);
    et = (EditText) findViewById(R.id.editText1);
    b = (Button) findViewById(R.id.button1);

    b.setOnClickListener(this);

    LoadPrefs();

    }

    [/HIGH]

    Can anyone see what im doing wrong?
     



    1. Download the Forums for Android™ app!


      Download

       
  2. alostpacket

    alostpacket Over Macho Grande?

    Your intent filter is mismatched, but I would just remove the intent filter and target the class specifically, unless you need a specific action

    -----------------------
    in your xml you have
    [HIGH]<action android:name="android.intent.action.SETTINGS" /> [/HIGH]but when you launch the intent you are asking for something else

    [HIGH]"com.example.newapplication.SETTINGS"[/HIGH]----------------------
    Instead I would do this:
    [HIGH]//ACTION_VIEW is a predefined Android intent action
    //you do not need a filter for it
    Intent i = new Intent(Intent.ACTION_VIEW);

    //this refers to the current activity
    i.setClass( this, MySettings.class );

    this.startActivity(i)
    [/HIGH]

    ----------------------
    You should really try to follow java naming conversions also.

    It will make it easier for you to read other people's code, and others to read yours.


    Types and Classes are TitleCase
    fields and methods and local variables are camelCase
    constants are CAPS_UNDERSCORE

     
    Atkinson_88 likes this.
Loading...

Share This Page

Loading...