You should be using an Allocation to transfer data between both sides (Java and RenderScript). If you declare an rs_allocation in your .rs file with a simple function:
rs_allocation ai;
void foo() {
int i = rsGetElementAt_int(ai, 0);
rsSetElementAt_int(ai, i + 1, 0);
}
You then create and attach an appropriate Allocation from the Java side:
RenderScript mRS = RenderScript.create(mCtx);
ScriptC_s mScript = new ScriptC_s(mRS);
Type t = new Type.Builder(mRS, Element.I32(mRS)).setX(1).create();
Allocation ai1 = Allocation.createTyped(mRS, t);
int i1[] = new int[1];
mScript.set_ai(ai1);
i1[0] = 777;
ai1.copyFrom(i1); // Copies contents of i1 into ai1 Allocation
mScript.invoke_foo();
ai1.copyTo(i1); // Copies contents of ai1 back to i1
// i1[0] now has the value 778
Obviously, you can use larger multidimensional buffers as well, but you just access them using 1 dimension from Java. You can also read/write these buffers from kernels (hence the Allocation parameters to forEach functions).