Android原生应用程序的命令行参数 [英] Android native application command line arguments

查看:205
本文介绍了Android原生应用程序的命令行参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有:

void android_main(struct android_app* state)

是否有可能获得用来启动从 android_app <​​/ code>结构应用程序的命令行参数?如果没有,是否有任何其他的意思,让他们使用C ++调用(我不能使用Java code)?

Is it possible to get command line arguments used to start the application from android_app structure? If not, is there any other mean to get them using C++ calls(I can't use Java code)?

推荐答案

Android应用程序没有应用程序唯一的命令行参数,因为没有执行exec()调用,以启动它们。

Android application processes do not have application-unique command line arguments, because no exec() call is made to start them.

通常情况下,当一个Shell启动一个程序,它叉自己创建一个新的进程,然后在这个过程中直接​​调用exec()来替换正在执行的一个shell程序的图像。该ARGC&放大器; argv的变量从传递到exec()的参数的。

Normally, when a shell launches a program, it forks itself to create a new process and then in that process immediately calls exec() to replace the shell program image with the one being executed. The argc & argv variables are derived from the parameters passed to exec().

但在Android上,为各种原因,包括共享code页全系统,一切正常应用程序是一个叫做受精卵的过程专门的儿童。没有执行exec()调用时,在code实现应用程序只需加载到进程后叉,而是和它的用户ID贬到该应用程序的。因为没有执行exec()调用,以建立新的命令行参数,唯一的这是可用于进程是那些使用Android的运行时的启动过程中,启动原受精卵的过程。这些可能包括VM上运行模式选项,但没有对具体的应用程序。

But on Android, for a variety of reasons including sharing code pages system wide, all normal app processes are specialized children of a process called zygote. No exec() call is made, instead after the fork the code implementing the application is simply loaded into the process, and it's userid demoted to that of the app. Because there is no exec() call to establish new command line arguments, the only ones which are available to the process are those used to start the original zygote process during the startup of the Android runtime. Those might include vm run mode options, but nothing about the specific app.

应用程序,并在活动或服务对象,响应于意图被启动。正如在评论已经指出的,意图对象有许多可视参数给接收器,其中的一些发挥作用非常像命令行参数将在更传统的系统。功能上,它是意图对象哪里会看有用的那些领域。

App processes, and the Activity or Service objects within, are started in response to Intents. As has been pointed out in comments, the Intent object has a number of parameters visible to the receiver, some of which play roles very much like command line arguments would in a more traditional system. Functionally, it is those fields of the Intent object where it would be useful to look.

和作为Nobu餐厅游戏点意见指出,本机活动并不功能不同 - 它仍然是一个普通的基于虚拟机的应用程序有很多关键的Java code的,它只是第三方开发者只写JNI库,配备必要的Java code已经与系统包装。

And as Nobu Games points point in comments, a "Native Activity" is not functionally that different - it is still a regular VM-based app with a lot of critical Java code, it's just that the 3rd party developer only writes jni libraries, with the necessary java code already packaged with the system.

这篇关于Android原生应用程序的命令行参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆