0

我想在两个活动之间传递一个结果,但是它以某种方式进入某个循环或 this.startActivity(pIntent) 中的任何内容,然后强制关闭。这是我第一个活动的核心代码。它计算一些东西,然后我想传递 double[] passResults 变量:

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);
}

然后我想以这种方式在另一个活动中捕捉它:

public class ScatterGraph extends DisplayMessageActivity{

public Intent getIntent(Context context) {

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

这是 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)

感谢您帮助我,我真的坚持这一点。我是android开发的新手,几个小时后找出解决方案。

4

1 回答 1

2

您正试图DisplayMessageActivity从自身内部启动,从而创建一个无限的“循环”。这会使您的应用程序内存不足。

代替:

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

和:

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

构造函数的第二个参数Intent(Context, Class<?>)应该是您希望启动的活动类,而不是原始活动。

于 2013-10-29T20:21:43.840 回答