0
我想在兩個活動之間傳遞一個結果,但不知何故它在某些循環或任何在this.startActivity(pIntent)中,然後強制關閉。這是我第一次活動的核心代碼。其計算的東西之後,我想通過雙[] passedResults變量:通過活動之間的意圖傳遞變量的問題
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開發新手,並在幾個小時後找出解決方案。
感謝您的快速答疑。現在,我首先嚐試將ScatterGraph.class添加到我的AndroidManifest.xml,就像這個' ',因爲LogCat說我還沒有添加。但在此之後再次出現內存泄漏的錯誤。請注意,我想在使用例如「後退箭頭」關閉第一個活動並使用按鈕開始第二個活動之後使用該結果,之後再重新使用結果以在圖形上顯示。謝謝您的幫助! –
我不確定你的流程是什麼,但是你應該根據我的回答明確地改變你的代碼(以避免DisplayMessageActivity無限期啓動)。另外,我想你可能對'startActivityForResult()'(而不是'startActivity()')感興趣。它會讓你從活動中捕捉重新調整的價值。 – kamituel
我試過'startActivityForResult(pIntent,1)',我改變了之前提到的'Intent pIntent = new Intent(this,ScatterGraph.class);'也把ScatterGraph.class添加到清單中,正如我前面提到的。但情況是相同的'eglMakeCurrent失敗EGL_BAD_ALLOC'。 :(待續... –