我想在两个活动之间传递一个结果,但不知怎的,它会在某个循环中或者在this.startActivity(pIntent)中进行,然后强制关闭。这是我的第一个活动的核心代码。它计算了一些东西,之后我想传递double []的传递结果变量:
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的新手,并在几个小时后找出解决方案。
答案 0 :(得分:2)
您正尝试从内部启动DisplayMessageActivity
,从而创建一个无限循环&#34;。这会使您的应用内存不足。
替换:
Intent pIntent=new Intent(this,DisplayMessageActivity.class);
使用:
Intent pIntent=new Intent(this,ScatterGraph.class);
Intent(Context, Class<?>)
构造函数的第二个参数应该是您要启动的Activity类,而不是原始活动。