My Problem: In MainActivity I start to download some data from the Internet via XML Parser. This data is displayed on every Screen of my App. It is like a Database.
While downloading and saving data, the user of the App can navigate through the hole app. If downloading and saving data is finished, I want to detect and reload the current foreground Activity. I need to do this, to display the new data.
I can detect the current Activity with the ActivityManager and can start it with the ComponentName with the method "startActivity(Intent.makeMainActivity(componentName)". But then the old activity is also there when I navigate back with the ActionBar-BackButton. I do this in the AsyncTasks onPostExecute-Method after downloading Data.
Any Ideas how to do it?
protected void onPostExecute(MainActivity.UrlParams result) {
Toast.makeText(result.contextMain, "Daten wurden erfolgreich aktualisiert!", Toast.LENGTH_LONG).show();
//Aktualisiert aktive Activity damit die neuen Daten angezeigt werden!
ActivityManager am = (ActivityManager) result.contextMain.getSystemService(ACTIVITY_SERVICE);
List<ActivityManager.RunningTaskInfo> taskInfo = am.getRunningTasks(1);
Log.d("topActivity", "CURRENT Activity ::" + taskInfo.get(0).topActivity.getClassName());
ComponentName componentInfo = taskInfo.get(0).topActivity;
componentInfo.getPackageName();
Intent intent = Intent.makeMainActivity(componentInfo);
result.contextMain.startActivity(intent);
//myApp.getCurrentActivity().set
}
BroadcastReceiver
in yourMainActivity
inonStart()
, and unregister it inonStop()
. Refresh your view in this receiver