0

how to get previous activity after scrolling last screen.in the following code i did as when last screen i wrote intent to call previous activity it was calling but it refresh all data in that and calling all the fields in that as null and calling i want to call as before calling how it is like that only.when i press backpress at bottom it is fine it getting the previous activity but when i call activity it gets null values.

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

};
image
  • 59
  • 1
  • 14

1 Answers1

1

you are starting prev activity again using startActivityForResult thats why you are getting your data refreshed for prev activity, so instead of calling it again you should call Activity.finish() on this activity so that it will open your prev activity with old data.

Your prev Activity will be added to stack when you start your current activity, so when you call finish on your current activity, os will kill this activity & pop prev activity from stack and retain its view. But here as you are calling startActivityForResult so it will prev activity afresh and push your current activity to stack

simply replace

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

with

finish()

Nitin Joshi
  • 128
  • 1
  • 10
  • please add some code how to write activity.finish() – image Apr 07 '14 at 06:11
  • you can simply call finish(), instead of Intent intent=new Intent(LearnMore.this,DeviceControlActivity.class); startActivityForResult(intent, 0); – Nitin Joshi Apr 07 '14 at 06:12
  • thanks it works.and i had another issue.that is now i am scrolling the screens but i want both by scrolling and when i click on it also it should move to next above is one class from that i am calling http://stackoverflow.com/questions/22861515/how-to-get-screens-by-clicking-and-by-last-screen-clicking-it-should-to-previous – image Apr 07 '14 at 06:16
  • once check http://stackoverflow.com/questions/22861515/how-to-get-screens-by-clicking-and-by-last-screen-clicking-it-should-to-previous and help me. – image Apr 07 '14 at 06:16
  • nick otherwise use only on tap/click on surface it should move to next screen. – image Apr 07 '14 at 06:45
  • please check this http://stackoverflow.com/questions/23005637/how-to-fill-the-color-of-image-according-to-percentage-of-textview-in-android/23005844?noredirect=1#comment35138813_23005844 – image Apr 11 '14 at 07:38
  • hi nick please check this http://stackoverflow.com/questions/23009657/how-to-change-the-image-color-in-imageview-according-to-percentage-and-fill-colo – image Apr 11 '14 at 10:20