You're welcome to any help. Android is such a royal pain that the more shared fixes the better.
on your problem; i've always run into trouble detaching contexts. A while back i tried to have contexts not attached to the top-level component. Whenever the hierarchy or visibility changes, it blows the OGL context. I tried working around this but it got worse.
Launching intents locks up. This can be fixed by decoupling the juce thread. you're calling into juce from java, then back into java then launching an intent, then expect to return to juce. decouple your intents making them async.
here's an example of how i launch an android file selector (in this case to load an image).
in my activity:
private static final int SELECT_PICTURE = 1;
private long pickImageCallback = 0;
private String pickedImage;
// send the picked image filepath back to juce
private native void notifyPickImage(long callback, String path);
// initiate selection of an image or file selector.
// when selected `notifyPickImage' is called with the initial callback
// and the selected `path'
public final void pickImage(long callback)
{
pickImageCallback = callback;
post(new Runnable()
{
@Override
public void run() {
Intent intent = new Intent();
intent.setType("image/*");
intent.setAction(Intent.ACTION_GET_CONTENT);
intent.putExtra(Intent.EXTRA_LOCAL_ONLY, true);
startActivityForResult(Intent.createChooser(intent,
"Select Picture"), SELECT_PICTURE);
}
});
}
then..
public void onActivityResult(int requestCode, int resultCode, Intent data)
{
if (requestCode == SELECT_PICTURE && resultCode == RESULT_OK)
{
Uri uri = data.getData();
// can be null
String path = getPicturePath(uri);
if (path != null && pickImageCallback != 0)
{
//Toast.makeText(this, path,Toast.LENGTH_LONG).show();
// store the chosen file path and decouple the
// callback so that the intent can be cleared down
pickedImage = path;
post(new Runnable()
{
@Override
public void run()
{
if (pickedImage != null
&& pickImageCallback != 0)
notifyPickImage(pickImageCallback,
pickedImage);
}
});
}
}
also for completeness (incase this code is useful for you).
private final String getPicturePath(Uri uri)
{
String path = null;
String scheme = uri.getScheme();
if (scheme.equals("content"))
{
// use content resolver
String[] projection = { MediaStore.Images.Media.DATA };
Cursor cursor = getContentResolver().query(uri, projection, null, null, null);
if (cursor != null)
{
int column_index =
cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
if (cursor.moveToFirst())
path = cursor.getString(column_index);
cursor.close();
}
}
else if (scheme.equals("file"))
{
// when using the file manager
path = uri.getPath();
}
return path;
}