简体   繁体   中英

Android: onResume() not called after pressing home button

I have an activity that makes a call to a remote server when it's started. The thing is, that when the app is on the background, and the server creates new content, when restoring my app, this new content is not seen unless the app is killed and started again.

I put the code that gets all this info from the server in the 'onResume()' method, which works when the app is killed and started again, but not if it's only sent to the background pressing the home button.

Why doesn't the 'onResume()' method get call? How can I do to have it called?

Thanks a lot in advance!

This is the code I have:

@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());
    }

Right, the problem was mine: my activity redirected to a fragment (it was a splash acitivity and when it finished, it would start the fragment). And it's in this fragment where I should have put the 'onResume()'.

Thanks everybody for the help!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM