mardi 30 décembre 2014

Destroy activity containing two fragments after clicking Andorid Back Button


Vote count:

0




)


I have problem, and I can't find any solution. I have Maps_Activity, which contains two fragments. Both fragments show google maps v2 and I display them on screen thanks to two ActionBar tabs.


The problem is appearing when I want to return to previous activity. When I click Android back button, my whole application turns down, shows pupup, that my application was stopped.


What I should add to my code to remove this error?


Maps_Activity.java



package com.example.user.elderly2;

import android.app.ActionBar;
import android.app.Activity;
import android.app.Fragment;

import android.os.Bundle;


public class Maps_Activity extends Activity {

ActionBar actionBar;
Fragment fragmentTab1 = new Medical_Shops_Map();
Fragment fragmentTab2 = new Medical_Clicnics_Map();

@Override
public void onCreate(Bundle arg0) {
super.onCreate(arg0);
setContentView(R.layout.activity_maps_);


actionBar=getActionBar();
actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);

ActionBar.Tab tab1=actionBar.newTab();
tab1.setText("Medical Shops");
tab1.setTabListener(new TabListener(fragmentTab1));

ActionBar.Tab tab2=actionBar.newTab();
tab2.setText("Medical Clinics");
tab2.setTabListener(new TabListener(fragmentTab2));



actionBar.addTab(tab1);
actionBar.addTab(tab2);


}

}


One of the fragments:



package com.example.user.elderly2;

import android.os.Bundle;
import android.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;

import com.google.android.gms.maps.MapFragment;



public class Medical_Clicnics_Map extends Fragment {




@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {

return (LinearLayout) inflater.inflate(R.layout.medical__clicnics__map, container, false);
}




@Override
public void onDestroyView() {

MapFragment f = (MapFragment) getFragmentManager().findFragmentById(R.id.map1);
if (f != null)
getFragmentManager().beginTransaction().remove(f).commit();

super.onDestroyView();
}



}


Any ideas? Plz help.



asked 2 mins ago







Destroy activity containing two fragments after clicking Andorid Back Button

Aucun commentaire:

Enregistrer un commentaire