Implement Android activities in GMA
Androidâ„¢ activities can be bundled with your GMA app and called from the Genero code.
A Java-based extension that interacts with the end user must be implemented as an Android Activity, by using the android.app.Android
class.
In order to use your Android Activity from the program, it must be integrated in the mobile app Android package (.apk), which is created in the Genero Studio deployment procedure.
This code example implements a simple Android Activity:
package com.myextension;
import android.app.Activity;
import android.os.Bundle;
import android.widget.TextView;
public class MyActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Button button = new Button(this);
button.setText("Quit");
setContentView(button);
button.setOnClickListener(
new View.OnClickListener() {
public void onClick(View v) {
int resultCode = RESULT_OK;
Intent resultData = new Intent();
resultData.putExtra("MyKey", "MyValue");
setResult(resultCode, resultData);
finish();
}
});
}
}
In order to execute this activity from a Genero app, use the
startActivity
front
call:MAIN
DEFINE data, extras STRING
MENU
ON ACTION activity ATTRIBUTES(TEXT="Call bundled activity")
CALL ui.Interface.frontCall("android", "startActivityForResult",
["android.intent.action.VIEW", NULL, NULL, NULL,
"com.myextension.MyActivity"],
[ data, extras ])
MESSAGE "data=",data," / extras=",extras
ON ACTION quit
EXIT MENU
END MENU
END MAIN
Note: The component name (fifth parameter) of the startActivity front call does normally
take the APK package name followed by the Java Activity class name
(
apk-package-name/java-class-name
). The APK
Android package name can be defined for
the application project in the Genero Studio. When using an user-defined activity that is part of
the GMA binary archive, do not specify the APK package in the component parameter, because
the Java Activity class will be included in the current APK package. This is true when using the
customized GMA front-end in development mode, and in the final application that is deployed on the
device. For more details about the component parameter, see startActivity (Android).