Marco Lau
Marco Lau

Reputation: 619

Activity Declaration in AndroidManifest.xml

I have a runtime error on my stock quoting application. I have an app where you input your a stock (as in stock market) code and will list it with two buttons. One button to display a quote and the other to view more info from the web. The web function is fine but the app crashes when I hit the quote button.

LogCat is asking me whether I declared my activity in my AndroidManifest.xml. I am still new to Android development so this is the best of which I can analyze the problem. I am not sure where to look for these errors.

Just use 'mstf' as a stock code if you need to test a fix.

You can find my app here: https://github.com/xamroc/StockQuote/tree/bug-quote

I would also appreciate any tips on debugging tools or techniques for Android.

Upvotes: 24

Views: 109939

Answers (6)

megh_sat
megh_sat

Reputation: 424

so when ever you create a new class you have to create an activity in the "AndroidManifest.xml" file inside the application tag like this::

`

<application
    android:allowBackup="true"
    android:icon="@mipmap/ic_launcher"
    android:label="@string/app_name"
    android:roundIcon="@mipmap/ic_launcher_round"
    android:supportsRtl="true"
    android:theme="@style/AppTheme">
    <activity android:name=".mainActivity">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

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

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

`

Upvotes: 2

shadi
shadi

Reputation: 21

you should declare the activity in manifest xml by defining the launchMode to singleTask or singleInstance.example:

<activity android:name="com.example.h.myapplication.MainActivity" 
          android:launchMode="singleTask" >

enter image description here

Upvotes: 1

Manishika
Manishika

Reputation: 5564

You have two activities in your package, but have only declared one in manifest.

Declare the other Activity class:

Add this to your manifest:

<activity
     android:name="com.example.stockquote.StockInfoActivity"
     android:label="@string/app_name" />

Upvotes: 41

Niroj
Niroj

Reputation: 1114

Your Activity means you have to declare your each and every class in android manifest so that it recognizes them as the Activity.So after the end of the Activity main you can do following:

<activity
 android:name=".YourClassNAME"

/>

Upvotes: 1

Touchstone
Touchstone

Reputation: 5962

Source: http://developer.android.com/guide/components/activities.html

You must declare your activity in the manifest file in order for it to be accessible to the system. To declare your activity, open your manifest file and add an <activity> element as a child of the <application> element. For example:

<manifest ... >
  <application ... >
      <activity android:name=".ExampleActivity" />
      ...
  </application ... >
  ...
</manifest >

There are several other attributes that you can include in this element, to define properties such as the label for the activity, an icon for the activity, or a theme to style the activity's UI.

The android:name attribute is the only required attribute—it specifies the class name of the activity. Once you publish your application, you should not change this name, because if you do, you might break some functionality, such as application shortcuts.

Upvotes: 1

AndroidBegin.com
AndroidBegin.com

Reputation: 402

Insert this <activity android:name=".StockInfoActivity" ></activity> in your AndroidManifest.xml

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

    <uses-sdk
        android:minSdkVersion="9"
        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.stockquote.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.stockquote.StockInfoActivity" >
        </activity>
    </application>

Upvotes: 18

Related Questions