0

Even after the screen goes how to show the data in it.I read we can use shared preferences.But i have too many edittext and spinners in many screens.Also i use async class along with it, so it takes a lot of time to fetch data and come back.So when the screen goes off, the whole activity gets restarted again.The selections i made in spinners and editext goes off.So i think it is better to keep the screen turned on while the app is running since we use async task. How to keep the screen turned when app is running.

this.getWindow().setFlags(this.getWindow().getFlags() & ~WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON

How to avoid this screen restarting and keep the values inside spinners and editext?

zyonneo
  • 1,319
  • 5
  • 25
  • 63
  • You cannot assume a user will not turn off the screen, regardless of the current state of your app – Tim Feb 17 '15 at 08:25
  • 1
    The screen going off does NOT cause activity restart. Screen rotation might (in which case turning off activity restart may be an answer), but not turning off the screen. – Gabe Sechan Feb 17 '15 at 08:32
  • paste some more code, when screen goes to off state onpause and on stop functions called. – Pankaj Arora Feb 17 '15 at 10:40

1 Answers1

0

try using Bundle

in onCreate and onResume check if the bundle is empty or not and in onStop or onDestroy set the values in bundle.

This will solve your problem.

You can use it like this,

Intent intent = new
Intent(getApplicationContext(),SecondActivity.class);
intent.putExtra("Key",Value);  
startActivity(intent);

Now you can get the passed values like this,

Bundle extras = intent.getExtras(); 
String tmp = extras.getString("Key");
dvs
  • 644
  • 5
  • 14