按下后退按钮时,在标签中看不到地图

时间:2014-05-20 11:40:27

标签: android google-maps tabs

在我的应用程序中,我使用以下xml代码显示地图。

<fragment 
 android:id="@+id/map"
 android:layout_width="match_parent"
 android:layout_height="match_parent"
 android:name="com.google.android.gms.maps.MapFragment"/>

在第一个活动按钮中,单击我使用代码显示mapactivity。

            Intent intent=new Intent(getParent(),mapActivity.class).addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);

             View view = MapTab.group.getLocalActivityManager().startActivity("notification",intent).getDecorView();  
                // Again, replace the view  
             MapTab.group.replaceView(view);

在我的MapActivity类中,我使用以下代码显示地图。

map = ((MapFragment) getFragmentManager().findFragmentById(R.id.map)).getMap();
         map.getUiSettings().setAllGesturesEnabled(true);
         map.getUiSettings().setRotateGesturesEnabled(false);
         map.setMyLocationEnabled(true);
         bounds=new LatLngBounds(new LatLng(33.66535378579427, -117.90596008300781),
                new LatLng( 33.66890364313455, -117.89649188518524));
         BitmapDescriptor image = BitmapDescriptorFactory.fromResource(R.drawable.categorymap);
         GroundOverlayOptions groundOverlay = new GroundOverlayOptions()
         .image(image)
         .positionFromBounds(bounds)
         .transparency(0.1f)
         .anchor(0.1f, 0.5f);
         map.addGroundOverlay(groundOverlay);

通过使用此代码,地图显示正确。在按钮单击的MapActivity类中,我使用以下代码显示DetailsActivty类。

        Intent intent=new Intent(getParent(),DetailsActivity.class).addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);

         View view = MapTab.group.getLocalActivityManager().startActivity("notification",intent).getDecorView();  
            // Again, replace the view  
         MapTab.group.replaceView(view);

在后退按钮的DetailsActivity类中,我编写了以下代码。

MapTab.group.onBackPressed();

因此,通过使用此活动,当前活动(DetalmapActivity)已完成,并且先前的活动(MapActivity)已显示但地图不可见。banlk屏幕可见。这是maptab类。

public class MapTab  extends ActivityGroup{

   // Keep this in a static variable to make it accessible for all the nesten activities, lets them manipulate the view  
   public static MapTab group;  

   // Need to keep track of the history if you want the back-button to work properly, don't use this if your activities requires a lot of memory.  
   public static  ArrayList<View> history;  
   public static View view;

   @Override  
    protected void onCreate(Bundle savedInstanceState) {  
         super.onCreate(savedInstanceState);  

          this.history = new ArrayList<View>();           
          group = this; 

          Window wd= getLocalActivityManager().startActivity("History",new Intent(this,MapActivity.class).addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP));
          view=wd.getDecorView();
          replaceView(view);
      }  

   public void replaceView(View v) {  
               // Adds the old one to history  
    Log.e("View is","added");

       history.add(v);     
       //Log.e("arraylilst size is",String.valueOf(history.size()));    
       // Changes this Groups View to the new View.  
        this.setContentView(v);  
   }  

   public void back() {  
       if(history.size() > 0) {  
            history.remove(history.size()-1);  
            setContentView(history.get(history.size()-1));  
       }else {  
            finish();  
       }  
    }  

   @Override  
    public void onBackPressed() { 
       Tabs.check_tab=true;
    try{
        Log.e("onBackPressed","workinggg");
        MapTab.group.back();
    }catch(IndexOutOfBoundsException e)
    {
        finish();
    }


       return;  
   }  
} 

所以请指导我在我的代码中犯了什么错误。

0 个答案:

没有答案