Thread / Intent als externe klasse

ms_cikar

Mitglied
Hallo Leute,

in meinem Android Hauptklasse verwende ich die LocationListener.

Ich möchte die GPS Location Ermittlung separat in einer klasse packen und nur die Koordinaten als Parameter von meiner Hauptklasse lesen. Die Koordinaten Ermittlung soll im Hintergrund laufen.

Ich habe erst mit Intent probiert habe es nicht hinbekommen. Wie kann ich es machen ist Intent dafür geeignet oder sollte ich lieber Thread benutzen?

heir ist mein Code.


Code:
package com.example.location;






import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.location.Criteria;
import android.location.Location;
import android.location.LocationListener;
import android.location.LocationManager;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.TextView;
import android.widget.Toast;


public class MainActivity extends Activity implements LocationListener {
   
    double p1, p2;
   

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        LocationManager lm =(LocationManager)getSystemService(LOCATION_SERVICE);
        String provider = lm.getBestProvider(new Criteria(), true);
       
        lm.requestLocationUpdates( LocationManager.GPS_PROVIDER,0,0, this);
       
        if(provider == null){
            onProviderDisabled(provider);
        }
    }


    @Override
    public void onLocationChanged(Location location) {
       
         p1= location.getLatitude();
         p2= location.getLongitude();

        
       String str = "Latitude: "+location.getLatitude()+"Longitude: "+location.getLongitude();
       Toast.makeText(getBaseContext(), str, Toast.LENGTH_LONG).show();
      
       TextView text = (TextView)findViewById(R.id.txtpos);
       text.setText(String.valueOf(p1 +" "+ p2));

      
 
      
       TextView speed_ausgabe1 = (TextView)findViewById(R.id.btnlaenge);
       speed_ausgabe1.setText(String.valueOf(speed2));
      
       TextView speed_ausgabe2 = (TextView)findViewById(R.id.btnbreite);
       speed_ausgabe2.setText(String.valueOf(speedkmh));
       
    }


    @Override
    public void onStatusChanged(String provider, int status, Bundle extras) {
        // TODO Auto-generated method stub
       
    }


    @Override
    public void onProviderEnabled(String provider) {
        // TODO Auto-generated method stub
       
    }


    @Override
    public void onProviderDisabled(String provider) {
        AlertDialog.Builder builder =new AlertDialog.Builder(this);
        builder.setTitle("GPS is Disabled");
        builder.setCancelable(false);
        builder.setPositiveButton("Enable GPS", new DialogInterface.OnClickListener() {
           
            @Override
            public void onClick(DialogInterface dialog, int which) {
                Intent startGps = new Intent (android.provider.Settings.ACTION_LOCATION_SOURCE_SETTINGS);
                startActivity(startGps);
               
            }
        });
        builder.setNegativeButton("Leave Gps off",  new DialogInterface.OnClickListener() {
           
            @Override
            public void onClick(DialogInterface dialog, int which) {
                dialog.cancel();
               
            }
        });

        AlertDialog alert = builder.create();
        alert.show();
       
       
       
    }
}
 
Ähnliche Java Themen
  Titel Forum Antworten Datum
I Android Auf ImageView aus einem anderen Thread zugreifen liefert Fehlermeldung (App stürzt ab) Android & Cross-Platform Mobile Apps 5
J Android zugrif auf Thread nach Handy drehen. Android & Cross-Platform Mobile Apps 10
A Von verschiedenen Klassen auf Thread zugreifen Android & Cross-Platform Mobile Apps 2
M Android Stop Swipe Refresh aus anderem Thread Android & Cross-Platform Mobile Apps 2
G Thread in einer Service erstellen Android & Cross-Platform Mobile Apps 0
M App Programmierung: Thread starten und Variablenwerte oder Objekte mitgeben Android & Cross-Platform Mobile Apps 2
A Android Von einem Thread auf anderen zugreifen Android & Cross-Platform Mobile Apps 3
C new Thread oder setRunning = true/false Android & Cross-Platform Mobile Apps 12
C Auf innere (Thread)Klasse zugreifen, von anderer Klasse aus Android & Cross-Platform Mobile Apps 3
S Android Kommunikation zwischen UI -> Service -> Thread Android & Cross-Platform Mobile Apps 4
G Pause ohne sleep und ohne zweiten Thread Android & Cross-Platform Mobile Apps 5
G Pause im Programmablauf ohne extra Thread Android & Cross-Platform Mobile Apps 2
JAVAnnik Android Layout ändern in Thread Android & Cross-Platform Mobile Apps 2
Gossi Android Gossis Android Fragen Thread Android & Cross-Platform Mobile Apps 3
H Android ListView Images aus dem Internet via Thread Android & Cross-Platform Mobile Apps 3
L Android Thread Android & Cross-Platform Mobile Apps 4
Kidao Wie startet man ein Thread richtig? Android & Cross-Platform Mobile Apps 4
G Thread und Midlet Android & Cross-Platform Mobile Apps 1
W JSONARRAY per Intent an andere Activity übergeben und umwandeln ggbf. Android & Cross-Platform Mobile Apps 1
N Intent und finish() Problem Android & Cross-Platform Mobile Apps 5
B Android Open Folder Intent? Android & Cross-Platform Mobile Apps 3
G Broadcast Intent action ausählen Android & Cross-Platform Mobile Apps 2
A Activity Intent 'source not found' Android & Cross-Platform Mobile Apps 4
Kazudemruzo Android API/Library für externe Entwickler zur Verfügung stellen Android & Cross-Platform Mobile Apps 7
Flynn Text-File auf externe Speicherkarte schreiben Android & Cross-Platform Mobile Apps 1
F Externe Bibliotheken in Projekt einbinden Android & Cross-Platform Mobile Apps 5
P J2ME - Anbindung an externe Datenbank Android & Cross-Platform Mobile Apps 3

Ähnliche Java Themen

Neue Themen


Oben