Hi,
I have written a simple application which displays GPS data on screen
using Toasts.
The important parts of my code are below.
public class GPS extends Activity
{
private LocationManager lm;
private LocationListener ll;
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
if (savedInstanceState == null)
{
lm = (LocationManager)
getSystemService(Context.LOCATION_SERVICE);
ll = new MyLocationListener();
}
button1.setOnClickListener(new View.OnClickListener()
{
public void onClick(View v)
{
if(first time button is pressed)
lm.requestLocationUpdates(LocationManager.GPS_PROVIDER, 1000, 0, ll);
else
lm.removeUpdates(ll);
}
}
}
This application preforms perfectly until either the screens
orientation is changed or the back button is pressed.
If either of these happen then pressing the button causes a null
pointer exception for lm.
Why does changing the screens orientation or pressing the back button
cause all variables defined at the Activity class level to be set to
null?
How do I fix this issue?
--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en