0

I have a homescreen containing mapfragment and rss feeds, which loads on startup. I have another few activities that contains magfragments just bigger.

My problem is that when i move between activities they restart, i want them to remain loaded up for when i go back to that activity. To save the user from downloading data all over again.

Any feedback appreciated

Thank you

This is what i have been using;

back.setOnClickListener(new View.OnClickListener() { 
@Override
public void onClick(View arg0) {
Intent MapActivity = new Intent(getApplicationContext(),HomeActivity.class);    
startActivity(MapActivity);
}
});










  protected void onCreate(Bundle savedInstanceState) {
            requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);  
            super.onCreate(savedInstanceState);
            setContentView(R.layout.main); 
            getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.window_title);
            new MyTask().execute();

            map = ((MapFragment) getFragmentManager().findFragmentById(R.id.map)).getMap();
            map.moveCamera(CameraUpdateFactory.newLatLngZoom(-, 15000));
            map.animateCamera(CameraUpdateFactory.zoomTo(7), 2000, null);
            map.setMyLocationEnabled(true);
            map.setMapType(GoogleMap.MAP_TYPE_NORMAL);
            map.getUiSettings().setZoomControlsEnabled(true);
            map.getUiSettings().setMyLocationButtonEnabled(true);
            map.setTrafficEnabled(true);

            LocationManager lm = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
            Location lastLocation = lm.getLastKnownLocation(LocationManager.GPS_PROVIDER);
            // Get the location manager
            locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);

            Criteria criteria = new Criteria();
            provider = locationManager.getBestProvider(criteria, false);
            Location location = locationManager.getLastKnownLocation(provider);

            }

I dont use OnResume, is that my problem??

prophetz
  • 107
  • 2
  • 10

2 Answers2

1

use android onResume to load the properties from the bundle or simply save some data to a runtime DB structured class or a sqlite db, for more info read from the android developer site on using bundle for using onResume refer this SO thread

Community
  • 1
  • 1
crazyPixel
  • 2,301
  • 5
  • 24
  • 48
1

You need to check out fragment life-cycle, there is no difference between map-fragment to a regular fragment, its just an extension of the fragment class made by Google for their maps, try and Google around for that you can use this thread theoretically I would make a class of a db that holds all the relevant data you need and instantiate a new instance of it in an APP class (that's the wrap up for the whole application) on the fragment onPause i would have saved the relevant properties to it and in the fragment onResume check whether the bundle is null in case it is extract the whole relevant from the DB class and "poor" its content to the relevant places for the exact places to save and extract the date refer to the fragment life-cycle document on the android developer site.

Community
  • 1
  • 1
crazyPixel
  • 2,301
  • 5
  • 24
  • 48
  • is there tutorials out there you know of? Ive found example for fragment dbs but im not sure how to use it with onresume and onpause?? – prophetz Oct 01 '13 at 11:35
  • no sorry...you can try and google that, In case you cant handle that i'll try and post a code example later on I assume you are new to android so my best suggestion is that you start by doing a review on android fundamentals – crazyPixel Oct 01 '13 at 11:44
  • yes this my 1st application. A code example would be brilliant! Once i get the OnPause and OnResume working for the maps and RSS feeds the app will be complete. – prophetz Oct 01 '13 at 11:51
  • http://stackoverflow.com/questions/16409783/android-maps-stop-responding-after-resuming-fragment?rq= would this be what im looking for? – prophetz Oct 01 '13 at 12:13