簡體   English   中英

滾動上一個屏幕后如何獲取上一個活動

[英]how to get previous activity after scrolling last screen

在滾動上一個screen之后如何獲取上一個活動。在以下代碼中,我像上一個屏幕那樣編寫了調用先前調用的活動的意圖,但是它刷新了其中的所有數據並將其中的所有字段都調用為null並調用了我想要的就像在調用它之前那樣調用。當我在底部按backpress時,可以獲取上一個活動,但是當我調用活動時,它會得到空值。

                protected void onCreate(Bundle savedInstanceState) {
    // TODO Auto-generated method stub
    super.onCreate(savedInstanceState);

    setContentView(R.layout.learnmore);

    realViewSwitcher=(com.RealViewSwitcher)findViewById(R.id.realviewswitcher);

    mainlayout=(RelativeLayout)findViewById(R.id.mainlayout);
    final int[] backgrounds = { R.drawable.braven_1_bankpercentage,R.drawable.braven_2_outputs,
            R.drawable.braven_3_findme,R.drawable.braven_4_sos,R.drawable.braven_5_bearmode};
    for (int i = 0; i < 6; i++) {
        TextView textView = new TextView(getApplicationContext());
        textView.setGravity(Gravity.CENTER);
        try{
        textView.setBackgroundResource(backgrounds[i]);
        }

        catch(Exception e){
            e.printStackTrace();
        }


        realViewSwitcher.addView(textView);
    }

    realViewSwitcher.setOnScreenSwitchListener(onScreenSwitchListener);

}



private final RealViewSwitcher.OnScreenSwitchListener onScreenSwitchListener = new RealViewSwitcher.OnScreenSwitchListener() {

    @Override
    public void onScreenSwitched(int screen) {
        if(screen==5)
        {
            Intent intent=new Intent(LearnMore.this,DeviceControlActivity.class);
            startActivityForResult(intent, 0);
        }
        Log.d("RealViewSwitcher", "switched to screen: " + screen);
    }

};

您將使用startActivityForResult重新開始上一個活動,這就是為什么要刷新上一個活動的數據的原因,因此,您不必在此活動上調用Activity.finish() ,而不是再次調用它,以便它將使用舊數據打開您的上一個活動。

您的上一個活動將在您開始當前活動時添加到堆棧中,因此,當您調用當前活動的完成時,操作系統將終止該活動並從堆棧中彈出上一個活動並保留其視圖。 但是在這里,當您調用startActivityForResult ,它將重新啟動活動並將當前活動推入堆棧

只需更換

      Intent intent=new Intent(LearnMore.this,DeviceControlActivity.class);
      startActivityForResult(intent, 0);

finish()

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM