Warum kommt manchmal null raus?

Hallo. Ich mache gerade eine App, die den Standort des Users finden soll. Manchmal klappt es und manchmal kommt null raus. Hier mal der Code:

lManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, locationTracker);
lManager.requestSingleUpdate(LocationManager.GPS_PROVIDER, locationTracker, null);
userLocation = locationTracker.lastUserLocation;

Location gpsLocation = null;
Location networkLocation = null;
Location passiveLocation = null;

try {
    gpsLocation = lManager.getLastKnownLocation(LocationManager.GPS_PROVIDER);
} catch (SecurityException e) {
    Toast.makeText(getActivity(), "Error: SecurityException. (" + e + ")", Toast.LENGTH_SHORT).show();
}

try {
    networkLocation = lManager.getLastKnownLocation(LocationManager.NETWORK_PROVIDER);
} catch (SecurityException e) {
    Toast.makeText(getActivity(), "Error: SecurityException. (" + e + ")", Toast.LENGTH_SHORT).show();
}

try {
    passiveLocation = lManager.getLastKnownLocation(LocationManager.PASSIVE_PROVIDER);
} catch (SecurityException e) {
    Toast.makeText(getActivity(), "Error: SecurityException. (" + e + ")", Toast.LENGTH_SHORT).show();
}

if (gpsLocation != null) {
    userLocation = gpsLocation;
} else if (networkLocation != null) {
    userLocation = networkLocation;
} else if (passiveLocation != null) {
    userLocation = passiveLocation;
} else if(locationTracker.lastUserLocation != null) {
    Toast.makeText(getActivity(), "Using last known location", Toast.LENGTH_SHORT).show();
    userLocation = locationTracker.lastUserLocation;
} else {
    Toast.makeText(getActivity(), "Error: Unable to get your location. Try Again.", Toast.LENGTH_SHORT).show();
    userLocation = null;
}

Das ist der Code, der onClick auf einen Button ausgeführt wird. in meiner onViewCreate Methode hab ich außerdem noch:

lManager = (LocationManager) getActivity().getSystemService(Context.LOCATION_SERVICE);
if(getActivity().checkPermission(Manifest.permission.ACCESS_FINE_LOCATION, Process.myPid(), Process.myUid()) == PackageManager.PERMISSION_GRANTED) {
    lManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, locationTracker);
}

Was ich nur nicht verstehe, wieso genau kommt da denn manchmal null raus? Ich sende doch eine request damit der Standort geupdatet wird. Jemand vielleicht eine Idee?

Danke im Voraus und lg.

P.S.:

Getestet auf ZTE Blade V10 (Android 9, API Level 29). Die ganze App ist auf Level 21.

PC, Computer, Handy, Internet, Software, App, Technik, programmieren, Java, GPS, Android, GPS Ortung, Softwareentwicklung, Technologie
Convertible oder Laptop?

Hallo!

Fange im Oktober mein Studium an (Kindheitspädagogik) und suche dafür ein mobiles Gerät für den Hochschulalltag.

Meine Entscheidung liegt jetzt zwischen Convertible (Tablet + Laptop in einem) oder einem normalen Laptop...

Tablet habe ich für mich ausgeschlossen, da ich auch fotografiere und einen SD-Kartenschlitz sowie USB Anschluss benötige.

Ich muss mit dem Gerät also Word/PowerPoint/Excel benutzen können, sowie ab und zu mal ein bisschen Bilder bearbeiten (nicht auf Profiniveau, da reicht Photoshop Express) und vielleicht mal ein bisschen Netflix, das ich am Abend schaue.

Der Akku sollte möglichst lange halten also am besten 8 Stunden oder mehr, 256gb Festplattenspeicher sollte reichen und zu schwer sollte das Gerät auch nicht sein (bis 1,5kg).

Wenn ich etwas recherchiere nutze ich sehr gerne die Funktion eines Tablets, genauso beim Netflix schauen, Word und PowerPoint lässt sich aber logischerweise besser mit einer Tastatur verwenden. Einen Stand-PC habe ich auch noch zuhause und ich Vorlesungen werde ich vermutlich viel mit Stift und Block schreiben, weil ich schlecht mit Stiften auf Tablets schreiben kann und an einer Tastatur auch nicht so schnell bin.

Das Gerät sollte so um die 14" haben.

Ziemlich viel spricht also wahrscheinlich für ein Convertible, aber welches ist da gut? Ich bin ein wenig überfragt...

Oder doch Laptop? Welcher ist da gut?

Computer, Studium, Technik, Technologie, Convertible Notebook, Laptop

Meistgelesene Beiträge zum Thema Technologie