如何调用另一个项目的活动?项目

2023-09-12 23:45:03 作者:远方的情书

您好我是新来的Andr​​oid和我创建了2个项目。

Hi I am new to android and I have created 2 projects.

现在我想调用的第二个项目的活动,从在点击一个按钮的第一个项目。

Now I want to call an activity in the second project from the first project upon a button click.

第1项目只处理登录屏幕,当我点击登录按钮,我需要调用一个活动是present的第二个项目。

The 1st project only handles login screen and when I click on the login button I need to call an activity which is present in the second project.

我搜查了网,但没找到我正确理解任何教程。

I searched the net but didn't find any tutorials which I understood properly.

您好我发现下面的错误。

Hi I found the following error.

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

我已经宣布了明显不过的了。

I have declared the manifest as this.

<?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>

和我打电话的第二类像这样的活动。

And I am calling the activity in the 2nd class like this.

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

这是正确的?

Is this right??

推荐答案

据到Android,你可以通过该项目的图书馆,然后将其定义在清单文件,并调用它什么都想要的方式

According to Android you can handle this by making the project Library and then Define it in the manifest file and call it in what ever manner you want

有关解释我这样做按我的要求 要在按钮点击呼叫活动定义它的清单,其完整的包名,然后当你调用它的按钮,单击该新项目的活动将触发 样品要做到这一点是以下 在你的第一个项目的清单文件中定义了一些这样的事

for an explanation i did this as per my requirement the activity you want to call on Button click Define it in the Manifest with its full package name and then when you call it on button click the activity of the new project will trigger the sample to do this is following in the manifest file of your 1st project define some thing like this

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

    </activity>

在包名称定义要呼叫和包名后给活动的名称活动的完整路径 希望这会为你工作,因为这工作适合我

in the package name define the full path of the the activity you want to call and after the package name give the name of the activity hope this will work for you as this worked perfect for me