How to run startActivity once jME has started

I am trying to setup and email to be sent from within my jME android app. To send the email, I have created the following class:

[java]public class SendEmailActivity extends Activity {
* Called when the activity is first created.
public void onCreate(Bundle savedInstanceState) {
Log.d(“MyDebug”, “About to create email activity…”);
Log.d(“MyDebug”, “Just created email activity.”);

    // Get the file to send
    Intent intent = getIntent();
    String filePath = intent.getExtras().getString("filePath");
    // Create an intent to send the email
    Intent i = new Intent(Intent.ACTION_SEND);
    i.putExtra(Intent.EXTRA_EMAIL, new String[]{""});
    i.putExtra(Intent.EXTRA_SUBJECT, "Motion Capture Data");
    i.putExtra(Intent.EXTRA_TEXT, "Here is the data from your latest motion capture");
    // Grab file
    File fileToSend = new File(filePath);
    Uri fileUri = Uri.fromFile(fileToSend);
    i.putExtra(Intent.EXTRA_STREAM, fileUri);
    Log.d("MyDebug", "Trying to send email...");
    try {
        startActivity(Intent.createChooser(i, "Send mail..."));
    } catch (android.content.ActivityNotFoundException ex) {
        Log.d("MyDebug", "There are no email clients installed");


This code works great when I call it from onCreate inside of MainActivity. However, I want to prompt this activity from within the jME update loop. I have created an AppState on the Android side that gives me access to the jME update loop and when I start this state, I be sure to pass the MainActivity’s context to it. Inside I have this:

[java] @Override
public void update(float tpf) {


    if (firstLoop) {
        firstLoop = false;

        // This starts a new activity and sends the email with the text file
        Intent emailIntent = new Intent(context, SendEmailActivity.class);
        String filePath = Environment.getExternalStorageDirectory().toString() + "/MoCap/TomsFile.txt";
        emailIntent.putExtra("filePath", filePath);

This will successfully launch the email client and I am able to send the email as I would expect. However, when I am finished with the email and I should return back to the jME loop, I get a OpenGL 1285 error. Reading about this error, it looks to be a memory out of bounds error and can happen when large textures are loaded. Why is this error being reported? Also, I have no doubt that I may be trying to do this a crazy way. From what I have been reading, AndroidHarness starts up the jME application in a GLSurfaceView, is that correct? If this is the case, then jME is running in a glThread and I no longer have access to MainActivity? Or is there a way to access MainActivity so that I can start an activity without starting it from the context?


I doubt it will solve your memory issues. But I would implement a one time call like that using a callable. Like this:
application.enqueue( new Callable(){

        public Object call() throws Exception {
            // Your stuff here...
            return null;


That way you don’t clutter up your update loop with stuff that will only be executed once.

1 Like

Thanks for the heads up about queueing my activity. It was stupid of me to block like I did. That didn’t solve the memory issue, but I finally found the answer to my problem. I needed to add:

[java]((Activity) context).finish();[/java]

after my call to startActivity().


Can you please some more code showing the way you did it? How you access android methods in JME3 Game project? How you pass activity context into AppState class? I have very similar problem, because I want to launch another activity by pressing Nifty GUI button in JME3.

Thanks for help.