【发布时间】:2017-05-18 22:52:03
【问题描述】:
我的问题: 在 MainActivity 中,我开始通过 XML Parser 从 Internet 下载一些数据。此数据显示在我的应用程序的每个屏幕上。它就像一个数据库。
在下载和保存数据的同时,应用程序的用户可以在洞应用程序中导航。如果下载和保存数据完成,我要检测并重新加载当前前台Activity。我需要这样做,以显示新数据。
我可以使用 ActivityManager 检测当前 Activity,并可以使用“startActivity(Intent.makeMainActivity(componentName)”方法从 ComponentName 启动它。但是当我使用 ActionBar-BackButton 导航返回时,旧的 Activity 也在那里. 下载数据后,我在 AsyncTasks onPostExecute-Method 中执行此操作。
任何想法如何做到这一点?
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
}
【问题讨论】:
标签: android android-activity android-asynctask reload activity-finish