Pikaa Pikaa - 6 months ago 28
Java Question

Jump to activity without button click

I am trying to go to next activity. After checking if the GPS is enabled
without any button click I am trying to jump to next activity.
But its not working

Is there any way to jump to nexy activity after checking if GPS is enabled
or after turning on GPS.




package app.example.joy;

import android.location.Location;
import android.location.LocationListener;
import android.location.LocationManager;
import android.os.Bundle;
import android.os.Handler;
import android.view.View;
import android.widget.Button;
import android.app.Activity;
import android.content.Intent;

public class Main extends Activity {

private LocationManager manager;
private LocationListener listner;

public void onCreate(Bundle savedInstanceState) {

manager = (LocationManager) getSystemService(LOCATION_SERVICE);
listner = new LocationListener() {

public void onStatusChanged(String s, int i, Bundle bundle) {

// TODO Auto-generated method stub


public void onProviderEnabled(String s) {

Intent i = new Intent(this, NextActivity.class);


public void onProviderDisabled(String s) {
// TODO Auto-generated method stub
Intent i = new Intent(


public void onLocationChanged(Location location) {
// TODO Auto-generated method stub

float latitude = (float) location.getLatitude();
float longitude = (float) location.getLongitude();

Intent i = new Intent(Main.this, NextActivity.class);
i.putExtra("Long", longitude);
i.putExtra("Lat", latitude);






I think the problem is that you've forgotten to even use the LocationManager that you instantiated. Try adding these two lines of code after instantiating the listener (at the end of your onCreate):

manager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 0, 0, listener);
manager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, listener);

These will register for location updates using the named provider, and a pending intent.