[英]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. 我正在尝试为Android构建库,在我的库中我试图从非Activity类调用Activity类。
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 但是,当我从非Activity调用Activity类时,它显示以下错误并且应用程序崩溃
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 这是我的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>
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. 活动在包com.example.library1中定义,但是以com.example.androidcamera3 / com.example.library1.Aa启动。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.