Reputation: 21
Hi I have a problem with my app. When I create a new project for Android 2.2 or lower my app works fine and my toast shows on screen but when I create a new project for 2.3 or 2.3.3 with the same code the toast does not appear at all. Also I have added the Textview update with in the main OnCreate thread but still me textview does not update. I need to solve the toast issue mainly though. thanks
public class Location extends Activity {
/** Called when the activity is first created. */
static String Text;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
LocationManager lm = (LocationManager)getSystemService(Context.LOCATION_SERVICE);
final TextView tv = (TextView)findViewById(R.id.textView1);
lm.requestLocationUpdates( LocationManager.GPS_PROVIDER, 0, 0, new LocationListener() {
private final String TAG = null;
@Override
public void onLocationChanged(android.location.Location location) {
// TODO Auto-generated method stub
Text = "My current location is: " + "Latitud = " + location.getLatitude() + "Longitud = " + location.getLongitude();
Context context = getApplicationContext();
int duration = Toast.LENGTH_SHORT;
Toast.makeText(context, Text, duration).show();
tv.setText(Text);
try
{
File root = Environment.getExternalStorageDirectory();
File gps = new File(root, "log.txt");
BufferedWriter out = new BufferedWriter(
new FileWriter(gps,true)) ;
out.write(Text);
out.write("");
out.close();
}
catch (IOException e) {
Log.e(TAG, "Could not write file " + e.getMessage());
}
}
Upvotes: 2
Views: 1573
Reputation: 73484
You have to call show() on the Toast.
Toast.makeText(context, Text, duration).show();
All you are doing is creating the Toast and not showing it.
The TextView update might be failing because of an Exception.
Upvotes: 3