Haris Hasan
Haris Hasan

Reputation: 30097

How to call native activity from java activity?

I know we can call an activity from another android activity as described in this question. My question is can we call a native activity from android activity through an intent or by using any other way? If yes, how?

Android.mk file of my native activity is following and native activity code is building fine

LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE    := mynativeactivity
LOCAL_SRC_FILES := main.c
LOCAL_LDLIBS    := -llog -landroid -lEGL -lGLESv1_CM
LOCAL_STATIC_LIBRARIES := android_native_app_glue
include $(BUILD_SHARED_LIBRARY)
$(call import-module,android/native_app_glue)

I am using this piece of xml to include my native activity in AndroidManifest.Xml file. And I think I am making a mistake here.

 //...rest of the xml including my main java activity here
  <activity android:name="android.app.NativeActivity" android:label="mynativeactivity" >
            <meta-data android:name="android.app.mynativeactivity"                  android:value="native-activity" />
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>

Can anyone tell me how can I fix XML above so that in my first java based activity I can do something like this (if it is possible)

 Intent intent = new Intent(this, mynativeactivity.class);
 startActivity(intent);

Currently I can't compile this code because compiler cannot locate mynativeactivity

Upvotes: 5

Views: 4518

Answers (3)

Qingping He
Qingping He

Reputation: 125

You probably don't need this, but just in case someone else stumbles on this

You need to change mynativeactivity.class to NativeActivity.class Also, make sure android_main calls app_dummy()

Upvotes: 3

Raka Indra
Raka Indra

Reputation: 9

try this :

Intent intent = new Intent(getApplicationContext(), MyNativeActivity.class);
                startActivity(intent);

Upvotes: 0

lost_bits1110
lost_bits1110

Reputation: 2420

If I understand correctly, your XML should look something like:

  <activity android:name="YourJavaActivity">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
  <activity     android:name="android.app.NativeActivity">
                <meta-data android:name="android.app.lib_name"
                android:value="YourNativeLibraryName" />
    </activity>

And replace 'YourJavaActivity' with the name of your Java activity, and 'YourNativeLibraryName' with the name of your library that gets created (without the 'lib' prefix).

If you derive from NativeActivity then you also need to change android.app.NativeActivity to the name of your derived class.

Then you can start your native activity as desired.

Upvotes: 2

Related Questions