【问题标题】:Android: onResume() not called after pressing home buttonAndroid:按下主页按钮后未调用 onResume()
【发布时间】:2012-11-13 14:13:09
【问题描述】:

我有一个在启动时调用远程服务器的活动。 问题是,当应用程序在后台,并且服务器创建新内容时,在恢复我的应用程序时,除非应用程序被终止并重新启动,否则不会看到这些新内容。

我将从服务器获取所有这些信息的代码放在“onResume()”方法中,该方法在应用程序被终止并重新启动时有效,但如果它仅发送到后台按下主页按钮则无效。

为什么'onResume()'方法没有被调用?我该怎么做才能调用它?

提前非常感谢!

这是我的代码:

@Override
    protected void onResume() {
        super.onResume();
        Server server = new Server(this);
        server.GetHighlights(10, 0, null);
        server.GetNews(10, 0, null);
        server.GetBrands(12, 0, null);
        Log.i("XS2", "Resume");
    }

    public void onCreate(Bundle icicle) {
        Log.i("XS2", "Create");
        super.onCreate(icicle);
        this.requestWindowFeature(Window.FEATURE_NO_TITLE);
        setContentView(R.layout.splash_media_player);
        mPreview = (VideoView) findViewById(R.id.surface);
        if (mPreview != null) {
            mHolder = mPreview.getHolder();
            mHolder.addCallback(this);
        }

//      Server server = new Server(this);
//      server.GetHighlights(10, 0, null);
//      server.GetNews(10, 0, null);
//      server.GetBrands(12, 0, null);

        // google analytics set up
        AnalyticsHelper.initializeTrackerInstance(getApplicationContext());
    }

【问题讨论】:

  • onResume 如果应用程序一直在后台并再次被带到前面,则始终调用。问题一定出在其他地方......也许显示一些代码......
  • onResume 正在被调用。你能告诉我们你的代码sn-p吗(例如在检索数据后更新ui)\
  • 我在调用 onResume() 和 onCreate() 时也输入了“Log”,在恢复我的应用程序时,我都看不到
  • @noloman 将日志放在 onResume 的开头,请再次检查
  • @SherifelKhatib 发生同样的事情,它甚至没有进入调试模式

标签: android android-activity lifecycle oncreate onresume


【解决方案1】:

是的,问题出在我的身上:我的活动重定向到一个片段(它是一个飞溅活动,当它完成时,它会启动片段)。我应该在这个片段中放置“onResume()”。

感谢大家的帮助!

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-08-12
    • 1970-01-01
    • 1970-01-01
    • 2021-04-20
    • 1970-01-01
    • 2023-03-30
    • 1970-01-01
    相关资源
    最近更新 更多