T
the_time
Ambitioniertes Mitglied
- 0
Hallo,
ich versuch einen Intent von onPostExecute zu onLocationChanged Methode zu übergeben aber die App restartet sich hineinander und es ist dann halt schwerig sie zu beenden. Im Logcat scheint ab und zu diese Fehlermedlung unten. Ohne das Intent code funktioniert die app ganz gut. Ich habe den Intent teil im code durch Kommentare wie "Ich habe diesen Part auch hinzugefügt " gekennzeichnet.
Error:
Beste Grüße,
the_time.
MainActiviy:
PostData class:
ich versuch einen Intent von onPostExecute zu onLocationChanged Methode zu übergeben aber die App restartet sich hineinander und es ist dann halt schwerig sie zu beenden. Im Logcat scheint ab und zu diese Fehlermedlung unten. Ohne das Intent code funktioniert die app ganz gut. Ich habe den Intent teil im code durch Kommentare wie "Ich habe diesen Part auch hinzugefügt " gekennzeichnet.
Error:
PHP:
05-17 21:19:12.553: E/ActivityThread(19497): Performing stop of activity that is not resumed: {com.bustracker/com.bustracker.MainActivity}
05-17 21:19:12.553: E/ActivityThread(19497): java.lang.RuntimeException: Performing stop of activity that is not resumed: {com.bustracker/com.bustracker.MainActivity}
05-17 21:19:12.553: E/ActivityThread(19497): at android.app.ActivityThread.performStopActivityInner(ActivityThread.java:3822)
05-17 21:19:12.553: E/ActivityThread(19497): at android.app.ActivityThread.handleStopActivity(ActivityThread.java:3910)
05-17 21:19:12.553: E/ActivityThread(19497): at android.app.ActivityThread.access$1200(ActivityThread.java:177)
05-17 21:19:12.553: E/ActivityThread(19497): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1477)
05-17 21:19:12.553: E/ActivityThread(19497): at android.os.Handler.dispatchMessage(Handler.java:102)
05-17 21:19:12.553: E/ActivityThread(19497): at android.os.Looper.loop(Looper.java:145)
05-17 21:19:12.553: E/ActivityThread(19497): at android.app.ActivityThread.main(ActivityThread.java:5944)
05-17 21:19:12.553: E/ActivityThread(19497): at java.lang.reflect.Method.invoke(Native Method)
05-17 21:19:12.553: E/ActivityThread(19497): at java.lang.reflect.Method.invoke(Method.java:372)
05-17 21:19:12.553: E/ActivityThread(19497): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1389)
05-17 21:19:12.553: E/ActivityThread(19497): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1184)
Beste Grüße,
the_time.
MainActiviy:
PHP:
public class MainActivity extends ActionBarActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
LocationManager lm = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
// Ich habe this hinzugefügt//
LocationListener ll = new myLocationListener(this);
lm.requestLocationUpdates(LocationManager.GPS_PROVIDER, 3000, 0, ll);
}
//Inner class in MainActivity
class myLocationListener implements LocationListener {
// Ich habe bContext and the constructor hinzugefügt//
final Context bContext;
public myLocationListener(Context context){
bContext = context;
}
@Override
public void onLocationChanged(Location location) {
PostData sender = new PostData();
// Ich habe context parameter hinzugefügt//
sender.post_data(jSONString, bContext);
// Ich habe diesen Part auch hinzugefügt//
Bundle extra = getIntent().getExtras();
if (extras != null) {
ArrayList<Integer> c = extras
.getIntegerArrayList("stop_route");
for (int item : c) {
System.out.println("The Intent is not empty: "
+ item);
}
}
}
PostData class:
PHP:
public class PostData {
String jSONString;
//Ich habe here routes variable hinzugefügt//
ArrayList<Integer> routes = new ArrayList<Integer>();
public PostData() {
super();
}
//Ich habe context hinzugefügt//
public void post_data(String jSONString, Context context) {
this.jSONString = jSONString;
new MyAsyncTask(context).execute(jSONString);
}
//Inner class in ht PostData class.
class MyAsyncTask extends AsyncTask<String, Integer, Void> {
//Ich habe here context variable und den Konstruktor hinzugefügt//
final Context mContext;
public MyAsyncTask(Context context){
mContext = context;
}
@Override
protected Void doInBackground(String... params) {
routes = data.getRoutes();
return null;
}
//Ich habe here diese Methode hinzugefügt//
@Override
protected void onPostExecute(Void result) {
// Intent with Conetxt of the Asyntask class and
Intent intent = new Intent(mContext, MainActivity.class);
intent.putExtra("stop_route", routes);
mContext.startActivity(intent);
}
}
}
Zuletzt bearbeitet: