Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/typo3/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android “前进”按钮导航到活动_Android - Fatal编程技术网

Android “前进”按钮导航到活动

Android “前进”按钮导航到活动,android,Android,我想在两个活动之间切换,但同时保留数据。我目前可以从主活动导航到结果活动并绘制一些数据,然后我可以按“上一步”按钮返回主活动,但如果我想再次前进到结果活动(图形),则所有数据都将消失,图形为空。我应该如何切换活动 主活动中的前进按钮方法: public void NextBtn(View view) { System.out.println("Next Button Pressed in Main Activity"); Intent next = new Intent(this, R

我想在两个活动之间切换,但同时保留数据。我目前可以从主活动导航到结果活动并绘制一些数据,然后我可以按“上一步”按钮返回主活动,但如果我想再次前进到结果活动(图形),则所有数据都将消失,图形为空。我应该如何切换活动

主活动中的前进按钮方法:

public void NextBtn(View view)  {
  System.out.println("Next Button Pressed in Main Activity");
  Intent next = new Intent(this, Results.class);
  //this extra is used to know what button called Results activity, if the call if from the NextBtn
  //part of the Results activity onCreate method should not be run since it will crash.
  next.putExtra("what", 1); 
  startActivity(next);
}
public void BackBtn (View view) {
  onBackPressed();  
}
结果活动中的后退按钮方法:

public void NextBtn(View view)  {
  System.out.println("Next Button Pressed in Main Activity");
  Intent next = new Intent(this, Results.class);
  //this extra is used to know what button called Results activity, if the call if from the NextBtn
  //part of the Results activity onCreate method should not be run since it will crash.
  next.putExtra("what", 1); 
  startActivity(next);
}
public void BackBtn (View view) {
  onBackPressed();  
}
完成结果活动代码:

package com.example.test;
import java.text.DecimalFormat;
import java.util.Arrays;
import com.androidplot.series.XYSeries;
import com.androidplot.xy.LineAndPointFormatter;
import com.androidplot.xy.SimpleXYSeries;
import com.androidplot.xy.XYPlot;
import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.graphics.Color;
import android.view.Menu;
import android.view.View;

public class Results extends Activity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        System.out.println("Results Activity Started");
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_results);

        Intent WhatBtn = getIntent();
        int what = WhatBtn.getIntExtra("what", 0);
        //if next button was pressed, break out of onCreate.
        if (what == 1) {
            System.out.println("In If Statement");
            return;
        }

        Intent intent = getIntent();
        double[] gain = intent.getDoubleArrayExtra("gainData");
        double[] phase = intent.getDoubleArrayExtra("phaseData");
        double[] X_axis = intent.getDoubleArrayExtra("Xaxis");

        XYPlot PhasePlot = (XYPlot) findViewById(R.id.PhasePlot);
        XYPlot GainPlot = (XYPlot) findViewById(R.id.GainPlot);

        // Create a couple arrays of y-values to plot:
        //loop is needed to get int[] to number[] and to interleave X & Y values
        Number[] gainNumbers = new Number[2*gain.length];
        Number[] phaseNumbers = new Number[2*phase.length];

        for (int i=1; i<=gain.length; i++) {
            gainNumbers[2*(i-1)] = X_axis[i-1];
            gainNumbers[(2*i)-1] = gain[i-1];
            phaseNumbers[2*(i-1)] = X_axis[i-1];
            phaseNumbers[(2*i)-1] = phase[i-1];
        }

        // Turn the above arrays into XYSeries':
        XYSeries series1 = new SimpleXYSeries(
                Arrays.asList(gainNumbers),          // SimpleXYSeries takes a List so turn our array into a List
                SimpleXYSeries.ArrayFormat.XY_VALS_INTERLEAVED, // Y_VALS_ONLY means use the element index as the x value
                "Series1");                             // Set the display title of the series

        // same as above
        XYSeries series2 = new SimpleXYSeries(Arrays.asList(phaseNumbers), SimpleXYSeries.ArrayFormat.XY_VALS_INTERLEAVED, "Series2");

        // Create a formatter to use for drawing a series using LineAndPointRenderer:
        LineAndPointFormatter series1Format = new LineAndPointFormatter(
                Color.rgb(0, 200, 0),                   // line color
                Color.rgb(0, 100, 0),                   // point color
                null);                                  // fill color (none)

        // add a new series' to the xyplot:
        GainPlot.addSeries(series1, series1Format);

        // same as above:
        PhasePlot.addSeries(series2,
                new LineAndPointFormatter(Color.rgb(0, 0, 200), Color.rgb(0, 0, 100), null));

        // reduce the number of range labels
        GainPlot.setTicksPerRangeLabel(3);

        // by default, AndroidPlot displays developer guides to aid in laying out your plot.
        // To get rid of them call disableAllMarkup():
        GainPlot.disableAllMarkup();
        //Lable plots
        GainPlot.setRangeLabel("Reflection Coefficient");
        GainPlot.setDomainLabel("Frequency (MHz)");
        PhasePlot.setRangeLabel("Phase (Degrees)");
        PhasePlot.setDomainLabel("Frequency (MHz)");
        PhasePlot.setTitle("Phase");
        GainPlot.setTitle("Gain");
        //Remove Legend
        GainPlot.getLayoutManager().remove(GainPlot.getLegendWidget());
        PhasePlot.getLayoutManager().remove(PhasePlot.getLegendWidget());
        //adust margins to avoid axis being cut off
        GainPlot.getGraphWidget().setGridPaddingRight(10);
        GainPlot.getGraphWidget().setGridPaddingTop(4);
        PhasePlot.getGraphWidget().setGridPaddingRight(10);
        PhasePlot.getGraphWidget().setGridPaddingTop(4);
        // only display whole numbers in domain labels
        GainPlot.getGraphWidget().setDomainValueFormat(new DecimalFormat("0"));
        PhasePlot.getGraphWidget().setDomainValueFormat(new DecimalFormat("0"));
    }

    public void start_sweep(View view) {
        //how to call start_sweep method in main activity from results activity
    }

    public void BackBtn (View view) {
        onBackPressed();    
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.results, menu);
        return true;
    }

}
package com.example.test;
导入java.text.DecimalFormat;
导入java.util.array;
导入com.androidplot.series.XYSeries;
导入com.androidplot.xy.LineAndPointFormatter;
导入com.androidplot.xy.SimpleXYSeries;
导入com.androidplot.xy.XYPlot;
导入android.os.Bundle;
导入android.app.Activity;
导入android.content.Intent;
导入android.graphics.Color;
导入android.view.Menu;
导入android.view.view;
公开课成绩扩大活动范围{
@凌驾
创建时受保护的void(Bundle savedInstanceState){
System.out.println(“结果活动已启动”);
super.onCreate(savedInstanceState);
setContentView(R.layout.activity\u结果);
Intent WhatBtn=getIntent();
int what=WhatBtn.getIntExtra(“what”,0);
//如果按下“下一步”按钮,则中断onCreate。
如果(what==1){
System.out.println(“In-If语句”);
返回;
}
Intent=getIntent();
double[]增益=意图。getDoubleArrayExtra(“增益”);
double[]phase=intent.getDoubleArrayExtra(“phaseData”);
double[]X_轴=intent.getDoubleArrayExtra(“Xaxis”);
XYPlot PhasePlot=(XYPlot)findViewById(R.id.PhasePlot);
XYPlot GainPlot=(XYPlot)findViewById(R.id.GainPlot);
//创建要打印的两个y值数组:
//循环用于将int[]转换为number[]并交错X&Y值
编号[]增益编号=新编号[2*增益长度];
编号[]相数=新编号[2*相长];

对于(inti=1;i,您可以在清单文件的结果活动中设置android:launchMode=“singleTop”。 因此,现在,如果您创建了一次活动(结果),那么向它发送另一个意图不会创建新活动,而是将前一个活动发送到前台

更多信息请参见

谢谢您的回复,这似乎没有帮助,但我确实意识到我把这件事复杂化了。我只是让下一个TBTN发送了与第一次调用的完全相同的意图来绘制数据。只是需要将一些数据全球化。但是再次发送相同的数据会导致不必要的数据流,而不仅仅是将数据带到f删除包含数据且只需要刷新的旧活动(转到前面)。但如果您的解决方案足够,则可以:)