5

こんにちは私はAndroidを初めて使用し、2つのプロジェクトを作成しました。

ここで、ボタンをクリックすると、最初のプロジェクトから2番目のプロジェクトのアクティビティを呼び出します。

最初のプロジェクトはログイン画面のみを処理し、ログインボタンをクリックすると、2番目のプロジェクトに存在するアクティビティを呼び出す必要があります。

ネットを検索しましたが、正しく理解できるチュートリアルが見つかりませんでした。

こんにちは私は次のエラーを見つけました。

01-30 08:36:47.230: E/dalvikvm(3408): Could not find class 'com.androidhive.googleplacesandmaps.MainActivity', referenced from method org.fluturasymphony.recommendation.LoginActivity$DownloadWebPageTask.doInBackground
01-30 08:36:52.587: E/AndroidRuntime(3408): FATAL EXCEPTION: AsyncTask #1
01-30 08:36:52.587: E/AndroidRuntime(3408): java.lang.RuntimeException: An error occured while executing doInBackground()
01-30 08:36:52.587: E/AndroidRuntime(3408):     at android.os.AsyncTask$3.done(AsyncTask.java:299)
01-30 08:36:52.587: E/AndroidRuntime(3408):     at java.util.concurrent.FutureTask.finishCompletion(FutureTask.java:352)
01-30 08:36:52.587: E/AndroidRuntime(3408):     at java.util.concurrent.FutureTask.setException(FutureTask.java:219)
01-30 08:36:52.587: E/AndroidRuntime(3408):     at java.util.concurrent.FutureTask.run(FutureTask.java:239)
01-30 08:36:52.587: E/AndroidRuntime(3408):     at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1080)
01-30 08:36:52.587: E/AndroidRuntime(3408):     at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:573)
01-30 08:36:52.587: E/AndroidRuntime(3408):     at java.lang.Thread.run(Thread.java:856)
01-30 08:36:52.587: E/AndroidRuntime(3408): Caused by: java.lang.NoClassDefFoundError: com.androidhive.googleplacesandmaps.MainActivity
01-30 08:36:52.587: E/AndroidRuntime(3408):     at org.fluturasymphony.recommendation.LoginActivity$DownloadWebPageTask.doInBackground(LoginActivity.java:69)
01-30 08:36:52.587: E/AndroidRuntime(3408):     at org.fluturasymphony.recommendation.LoginActivity$DownloadWebPageTask.doInBackground(LoginActivity.java:1)
01-30 08:36:52.587: E/AndroidRuntime(3408):     at android.os.AsyncTask$2.call(AsyncTask.java:287)
01-30 08:36:52.587: E/AndroidRuntime(3408):     at java.util.concurrent.FutureTask.run(FutureTask.java:234)
01-30 08:36:52.587: E/AndroidRuntime(3408):     ... 3 more

私はマニフェストをこれとして宣言しました。

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

    <uses-sdk android:minSdkVersion="9"
              android:targetSdkVersion="11" />
    <uses-permission android:name="android.permission.INTERNET" />    
    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
    <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
    <application android:icon="@drawable/ic_launcher" android:label="@string/app_name">
        <activity android:label="@string/app_name" android:name=".LoginActivity">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

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

        <activity android:name="org.achartengine.GraphicalActivity" />
        <activity android:name=".CategoryWiseSalesChartActivity" />
        <activity android:name=".ProductWiseSalesChartActivity" />
        <activity android:name="com.androidhive.googleplacesandmaps.MainActivity"/>
        <activity android:label="@string/home_screen" android:name=".HomeActivity" android:configChanges="orientation">            
        </activity>
        <activity android:label="@string/store_screen" android:name=".StoreActivity" android:configChanges="orientation">            
        </activity>
        <activity android:label="@string/store_list_screen" android:name=".StoreListActivity" android:configChanges="orientation">            
        </activity>
        <activity android:label="@string/location_screen" android:name=".StoreMapActivity" android:configChanges="orientation">            
        </activity>
        <activity android:label="@string/recommended_products_list_screen" android:name=".RecommendedProductsListActivity" android:configChanges="orientation">            
        </activity>
        <activity android:label="@string/category_wise_sales_screen" android:name=".CategoryWiseSalesActivity" android:configChanges="orientation">            
        </activity>
        <activity android:label="@string/product_wise_sales_screen" android:name=".ProductWiseSalesActivity" android:configChanges="orientation">            
        </activity>
                <uses-library android:name="com.google.android.maps" />


    </application>



</manifest>

そして、私はこのように2等の活動を呼んでいます。

Intent loginintent = new Intent("com.androidhive.googleplacesandmaps.MainActivity");
                        startActivity(loginintent);

これは正しいですか??

4

5 に答える 5

3

Androidによると、プロジェクトライブラリを作成し、マニフェストファイルで定義して、任意の方法で呼び出すことで、これを処理できます。

説明のために私は私の要件に従ってこれを行いましたボタンをクリックしてマニフェストに完全なパッケージ名で定義し、ボタンをクリックすると新しいプロジェクトのアクティビティがサンプルをトリガーしますこれはmanifestあなたの最初のプロジェクトのファイルで次のように定義されています

<activity 
        android:name="packagefull.activityname"
        android:theme="@android:style/Theme.NoTitleBar.Fullscreen">

    </activity>

パッケージ名で、呼び出したいアクティビティのフルパスを定義し、パッケージ名の後にアクティビティの名前を指定します。これが私にとって完璧に機能したので、これが機能することを願っています。

于 2013-01-30T05:06:00.693 に答える
2

これを使って:

Intent i = new Intent(Intent.ACTION_MAIN);
i.setComponent(new ComponentName("app package name", "app launch activity's classname"));
i.addCategory(Intent.CATEGORY_LAUNCHER);
startActivity(i);
于 2013-01-30T05:22:21.037 に答える
1

これは、アプリケーションを開発するための良い方法ではありません。ただし、これを実現する場合は、そのアプリケーションのマニフェストファイルでターゲットアクティビティのインテントフィルターを宣言し、ログインアクティビティからの暗黙的なインテントとして使用する必要があります。

プロジェクトAのマニフェストの内部:

<activity android:name="com.example.android.TargetActivity">
             <intent-filter>
                <action android:name="com.someone.wants.to.call.me"></action>
            </intent-filter>
</activity>

プロジェクトBの活動の内部:

Intent intent = new Intent("com.someone.wants.to.call.me");
         startActivity(intent);
于 2013-01-30T05:16:08.723 に答える
0
  1. マッププロジェクトのAndroidManifestファイルに、カスタムインテントフィルターを追加します

     <!-- add custom action -->
     <activity android:name="MapActivity"
                android:label="@string/mapLabel"
            >
                <intent-filter>
                    <action android:name="com.example.map.show" />
                </intent-filter>
            </activity>
    
  2. ログインボタンから、次のようにこのアクティビティを呼び出します。

インテントインテント=newIntent( "com.example.map.show"); startActivity(intent);

于 2013-01-30T05:13:16.843 に答える
-1

アプリケーションごとに1つのプロジェクトを使用する必要があります。ログインをアプリケーションの残りの部分から分割したい場合は、別のパッケージを使用できます。「プロジェクト」とはどういう意味か誤解しない限り?

于 2013-01-30T05:03:49.400 に答える