0

I want to pass a result between two activities, but somehow its go in some loop or whatever at the this.startActivity(pIntent), then force close. Here is my core code of the first activity. Its calculate something and after that I want to pass the double[] passedResults variable:

public class DisplayMessageActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    List<double[]> lokal = readCsv(getApplicationContext());
    ArrayList<String> collect = new ArrayList<String>();

    for (double[]sor : lokal) {

                mean(sor);
                String row = Double.toString(mean(sor));
                collect.add(row);                   
    }

    String result = "";
            for (int c=0; c<collect.size(); c++)
            {
                String curString = collect.get(c);
                result = result + curString + "\n";
            }

    String [] results = result.split("\n");
    double[] passedResults = new double[results.length];
    for(int i = 0; i < results.length; i++)
    {
        passedResults[i] = Double.parseDouble(results[i]);
    }

    //Passing?!
    Intent pIntent=new Intent(this,DisplayMessageActivity.class);
    pIntent.putExtra("sResults", passedResults);
    this.startActivity(pIntent);

    getActionBar().setDisplayHomeAsUpEnabled(true);


    Intent intent = getIntent();

        TextView textView = new TextView(this);
        textView.setTextSize(20);
        textView.setText("Results are the nexts:\n"+result);

        setContentView(textView);
}

Then I want to catch it in another activity this way:

public class ScatterGraph extends DisplayMessageActivity{

public Intent getIntent(Context context) {

    Bundle bundle = getIntent().getExtras();
    double[] recievedResults = bundle.getDoubleArray("sResults");
}

And here is the LogCat:

10-29 20:49:07.078: E/AndroidRuntime(19821): FATAL EXCEPTION: main
10-29 20:49:07.078: E/AndroidRuntime(19821): java.lang.IllegalStateException: eglMakeCurrent failed EGL_BAD_ALLOC
10-29 20:49:07.078: E/AndroidRuntime(19821):    at android.view.HardwareRenderer$GlRenderer.createSurface(HardwareRenderer.java:1069)
10-29 20:49:07.078: E/AndroidRuntime(19821):    at android.view.HardwareRenderer$GlRenderer.createEglSurface(HardwareRenderer.java:961)
10-29 20:49:07.078: E/AndroidRuntime(19821):    at android.view.HardwareRenderer$GlRenderer.initialize(HardwareRenderer.java:787)
10-29 20:49:07.078: E/AndroidRuntime(19821):    at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1502)
10-29 20:49:07.078: E/AndroidRuntime(19821):    at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:989)
10-29 20:49:07.078: E/AndroidRuntime(19821):    at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:4351)
10-29 20:49:07.078: E/AndroidRuntime(19821):    at android.view.Choreographer$CallbackRecord.run(Choreographer.java:749)
10-29 20:49:07.078: E/AndroidRuntime(19821):    at android.view.Choreographer.doCallbacks(Choreographer.java:562)
10-29 20:49:07.078: E/AndroidRuntime(19821):    at android.view.Choreographer.doFrame(Choreographer.java:532)
10-29 20:49:07.078: E/AndroidRuntime(19821):    at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:735)
10-29 20:49:07.078: E/AndroidRuntime(19821):    at android.os.Handler.handleCallback(Handler.java:725)
10-29 20:49:07.078: E/AndroidRuntime(19821):    at android.os.Handler.dispatchMessage(Handler.java:92)
10-29 20:49:07.078: E/AndroidRuntime(19821):    at android.os.Looper.loop(Looper.java:137)
10-29 20:49:07.078: E/AndroidRuntime(19821):    at android.app.ActivityThread.main(ActivityThread.java:5227)
10-29 20:49:07.078: E/AndroidRuntime(19821):    at java.lang.reflect.Method.invokeNative(Native Method)
10-29 20:49:07.078: E/AndroidRuntime(19821):    at java.lang.reflect.Method.invoke(Method.java:511)
10-29 20:49:07.078: E/AndroidRuntime(19821):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:795)
10-29 20:49:07.078: E/AndroidRuntime(19821):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:562)
10-29 20:49:07.078: E/AndroidRuntime(19821):    at dalvik.system.NativeStart.main(Native Method)

Thanks for helping me out, Im really stuck with this. Im new at android developing and figure out the solution after a couple of hours.

Hater Aulik
  • 11
  • 1
  • 4

1 Answers1

2

You are trying to launch DisplayMessageActivity from within itself, thus creating an infinite "loop". This makes your app run out of memory.

Replace:

Intent pIntent=new Intent(this,DisplayMessageActivity.class);

with:

Intent pIntent=new Intent(this,ScatterGraph.class);

Second argument to Intent(Context, Class<?>) constructor should be the Activity class you wish to launch, not the originating activity.

kamituel
  • 34,606
  • 6
  • 81
  • 98
  • Thanks for the fast answser. Now first I tried to add that ScatterGraph.class to my AndroidManifest.xml, like this `` because the LogCat says that I havent add that yet. But after that comes again that error with the memory leak. Note, I want to use that result after I close the the first activity with for example a "back arrow" and start the second activity with a button and after that reusing the result for displaying on a graph. Thanks for the help! – Hater Aulik Oct 29 '13 at 20:49
  • I'm not sure what your flow is, but you should definately change your code according to my answer (to avoid DisplayMessageActivity to launch itself indefinitely). Also, I think you might be interested in `startActivityForResult()` (instead of `startActivity()`). It'll let you capture the retuning value from the activity. – kamituel Oct 30 '13 at 07:03
  • I've tried that `startActivityForResult(pIntent, 1)` and I change what you mentioned before `Intent pIntent=new Intent(this,ScatterGraph.class);` also added the ScatterGraph.class to the manifest, as I mentioned before. But the situation is the same `eglMakeCurrent failed EGL_BAD_ALLOC`. :( To be continue... – Hater Aulik Oct 30 '13 at 19:40
  • My flow is: I click a button on the main screen of the application the activity of that button counting something in the background, after that display the results on the screen. Besides the displaying I want to store and pass the result (double array) to another activity, that I want to launch after I get back to the main screen and hit lets call the "Display button", then the activity starts reuse the results saved by further activity and display it as a graph and so on. Any idea what is my problem? Thanks in advance for the help! @kamituel – Hater Aulik Oct 30 '13 at 19:41