Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8667943
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T18:05:25+00:00 2026-06-12T18:05:25+00:00

My android application compirises two Activities: .MainActivity and android.app.NativeActivity. The latter is implemented purely

  • 0

My android application compirises two Activities: “.MainActivity” and “android.app.NativeActivity”. The latter is implemented purely in C++. On button click in “.MainActivity” I start a native one trying to pass some parameters:

public void pressedButton(View view)
{
    Intent intent = new Intent(this, android.app.NativeActivity.class);
    intent.putExtra("MY_PARAM_1", 123);
    intent.putExtra("MY_PARAM_2", 321);
    startActivity(intent);
}

How do I get MY_PARAM_1 and MY_PARAM_2 from within android.app.NativeActivity’s entry point (that is a C-function void android_main(struct android_app* state))?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T18:05:27+00:00Added an answer on June 12, 2026 at 6:05 pm

    In the android_app structure there’s a data member called activity of type ANativeActivity*. Inside the latter, there’s a JavaVM *vm and a misleadingly called jobject clazz. The clazz is actually a JNI-compliant object instance pointer to a Java object of type android.app.NativeActivity, which has all Activity methods, including getIntent().

    There’s a JNIEnv there, too, but it looks like it’s not attached to the activity’s main thread.

    Use JNI invokations to retrieve the intent, then extras from the intent. It goes like this:

    JNIEnv *env;
    state->activity->vm->AttachCurrentThread(&env, 0);
    
    jobject me = state->activity->clazz;
    
    jclass acl = env->GetObjectClass(me); //class pointer of NativeActivity
    jmethodID giid = env->GetMethodID(acl, "getIntent", "()Landroid/content/Intent;");
    jobject intent = env->CallObjectMethod(me, giid); //Got our intent
    
    jclass icl = env->GetObjectClass(intent); //class pointer of Intent
    jmethodID gseid = env->GetMethodID(icl, "getStringExtra", "(Ljava/lang/String;)Ljava/lang/String;");
    
    jstring jsParam1 = (jstring)env->CallObjectMethod(intent, gseid, env->NewStringUTF("MY_PARAM_1"));
    const char *Param1 = env->GetStringUTFChars(jsParam1, 0);
    //When done with it, or when you've made a copy
    env->ReleaseStringUTFChars(jsParam1, Param1);
    
    //Same for Param2
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

My Android application shows an AlertDialog on a button click. When I click on
An Android application has two activities. Activity A shows a list of items. Activity
I'm planning to start an application comprises of augmented reality in android. Proposed application
I want to set a button in my Android application that is comprised of
In android application for data storing and sharing in app which one is good
I am developing an Android application that would have an offline data in start
My android application needs another NATIVE application executable to run before the android one,
My android application is consists of 20+ activities. I want to perform some task
My android application works fine without these two lines: layMain= (LinearLayout) findViewById(R.id.layout_main); layMain.setOnTouchListener((OnTouchListener) this);
Android application should show Events happening in city as per day/month/year anywhere in the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.