Anand K
Anand K

Reputation: 233

How to call an Activity class from non-Activity in Android

I am trying to build library for android, in my library i am trying to call a Activity class from non-Activity class.

This is my non-Activity class

public class Library1  {

   Activity activity;
   public Library1(Activity activity){ 
      this.activity = activity;
     }

    public void captureImage() {
        intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
        fileUri = getOutputMediaFileUri(MEDIA_TYPE_IMAGE);
        intent.putExtra(MediaStore.EXTRA_OUTPUT, fileUri);
        Intent i1 = new Intent ( activity, Aa.class);
        context.startActivity(i1);
    }
}

This my Activity class which i want to call

 public class Aa extends Activity {

 public void someMethod()
 {
 } 

 }

But when i call Activity class from non-Activty it is showing following error and application is crashing

android.content.ActivityNotFoundException: Unable to find explicit activity class        
{com.example.androidcamera3/com.example.library1.Aa}; have you declared this 
activity in your AndroidManifest.xml?

This is my AndroidManifesto.xml

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.library1"
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.library1.Library1"
        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.library1.Aa" android:label="@string/app_name" />

</application>

Upvotes: 0

Views: 322

Answers (1)

Manish Mulimani
Manish Mulimani

Reputation: 17615

There is a spell mistake. [ acivity => activity ]

Change

<acivity android:name="com.example.library1.Aa" android:label="@string/app_name" />

to

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

Activity is defined in package com.example.library1, however it is launched as com.example.androidcamera3/com.example.library1.Aa.

Upvotes: 4

Related Questions