Issue
I'am having troubles with Googles MapView Activity.
The reason for my problem:
My application relies on many asynchronous events. When I start an Activity containing the Map, I've a template mechanism which adds and initializes the Map and relays all activity callbacks like onCreate(), onResume() to the map. All works fine!
But when this activity is restored from background my template mechanism is not yet ready to create the dynamic layout in onCreate(), hence I can't relay the lifecycle callbacks which are needed for the Map. In worst case, the Map is created after onResume().
This simplified code is for understanding the issue:
public class MapActivity{
List<Templates> templates;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
if (app.isInit())) {
initActivity();
}
templates.onCreate();
}
// init after templates are loaded
private void initActivity() {
templates = templateEngine.renderSomeTemplates()
}
@Override
protected void onResume() {
super.onResume();
templates.onResume()
}
public void onEventMainThread(InitAppEvent event) {
initActivity()
}
}
So my question.
Is there any way to add a google MapView programmatically during runtime without passing onCreate() and so on to it or do some lazy init?
Solution
Ok, I figured it out.
Apparently it's impossible to live without the callbacks as described in the docs: http://developer.android.com/reference/com/google/android/gms/maps/MapView.html
So I found a trick to force my activity to start all over again, as soon as my dependencies (templates) are ready.
If anyone is looking for a neat way to restart an activity: there is recreate()
http://developer.android.com/reference/android/app/Activity.html#recreate()
It basically finishes the activity and repeats the normal lifecycle from the beginning.
Answered By - JimVanB
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.