Which method is run when Home button pressed?
I have a Home replacement Activity from within which you can launch a number of apps. When you tap the Home button, you are returned to my Home replacement Activity.
As I understand, tapping the Home button creates an intent to launch the Home screen and then starts that intent (I might be wrong, please correct me if I am!). If this is the case, I'd expect the onCreate()
method to be run whenever the Home screen is created. On the other hand, when you launch another activity, the Home screen invokes onPause()
. So returning to it makes me assume onResume()
is invoked.
If someone could just offer some enlightenment into this matter, the basic question is whether onResume()
or onCreate()
gets called when I tap the Home button, but additional details are welcome, I'm working on stuff that utilizes this heavily and want to know a lot about it.
android oncreate onresume android-homebutton
add a comment |
I have a Home replacement Activity from within which you can launch a number of apps. When you tap the Home button, you are returned to my Home replacement Activity.
As I understand, tapping the Home button creates an intent to launch the Home screen and then starts that intent (I might be wrong, please correct me if I am!). If this is the case, I'd expect the onCreate()
method to be run whenever the Home screen is created. On the other hand, when you launch another activity, the Home screen invokes onPause()
. So returning to it makes me assume onResume()
is invoked.
If someone could just offer some enlightenment into this matter, the basic question is whether onResume()
or onCreate()
gets called when I tap the Home button, but additional details are welcome, I'm working on stuff that utilizes this heavily and want to know a lot about it.
android oncreate onresume android-homebutton
developer.android.com/guide/components/…
– Raghunandan
Jul 9 '13 at 15:58
Yeah, when the Home is put in the background, my question is what is called when you tap Home and return to the Home screen
– mike
Jul 9 '13 at 15:58
You may want to overrideonBackPressed()
– PatrickNLT
Jul 9 '13 at 16:00
add a comment |
I have a Home replacement Activity from within which you can launch a number of apps. When you tap the Home button, you are returned to my Home replacement Activity.
As I understand, tapping the Home button creates an intent to launch the Home screen and then starts that intent (I might be wrong, please correct me if I am!). If this is the case, I'd expect the onCreate()
method to be run whenever the Home screen is created. On the other hand, when you launch another activity, the Home screen invokes onPause()
. So returning to it makes me assume onResume()
is invoked.
If someone could just offer some enlightenment into this matter, the basic question is whether onResume()
or onCreate()
gets called when I tap the Home button, but additional details are welcome, I'm working on stuff that utilizes this heavily and want to know a lot about it.
android oncreate onresume android-homebutton
I have a Home replacement Activity from within which you can launch a number of apps. When you tap the Home button, you are returned to my Home replacement Activity.
As I understand, tapping the Home button creates an intent to launch the Home screen and then starts that intent (I might be wrong, please correct me if I am!). If this is the case, I'd expect the onCreate()
method to be run whenever the Home screen is created. On the other hand, when you launch another activity, the Home screen invokes onPause()
. So returning to it makes me assume onResume()
is invoked.
If someone could just offer some enlightenment into this matter, the basic question is whether onResume()
or onCreate()
gets called when I tap the Home button, but additional details are welcome, I'm working on stuff that utilizes this heavily and want to know a lot about it.
android oncreate onresume android-homebutton
android oncreate onresume android-homebutton
edited Jul 5 '17 at 14:23
Vadim Kotov
4,37953247
4,37953247
asked Jul 9 '13 at 15:57
mikemike
73311232
73311232
developer.android.com/guide/components/…
– Raghunandan
Jul 9 '13 at 15:58
Yeah, when the Home is put in the background, my question is what is called when you tap Home and return to the Home screen
– mike
Jul 9 '13 at 15:58
You may want to overrideonBackPressed()
– PatrickNLT
Jul 9 '13 at 16:00
add a comment |
developer.android.com/guide/components/…
– Raghunandan
Jul 9 '13 at 15:58
Yeah, when the Home is put in the background, my question is what is called when you tap Home and return to the Home screen
– mike
Jul 9 '13 at 15:58
You may want to overrideonBackPressed()
– PatrickNLT
Jul 9 '13 at 16:00
developer.android.com/guide/components/…
– Raghunandan
Jul 9 '13 at 15:58
developer.android.com/guide/components/…
– Raghunandan
Jul 9 '13 at 15:58
Yeah, when the Home is put in the background, my question is what is called when you tap Home and return to the Home screen
– mike
Jul 9 '13 at 15:58
Yeah, when the Home is put in the background, my question is what is called when you tap Home and return to the Home screen
– mike
Jul 9 '13 at 15:58
You may want to override
onBackPressed()
– PatrickNLT
Jul 9 '13 at 16:00
You may want to override
onBackPressed()
– PatrickNLT
Jul 9 '13 at 16:00
add a comment |
3 Answers
3
active
oldest
votes
tapping the Home button creates an intent to launch the Home screen and then starts that intent
Correct.
If this is the case, I'd expect the onCreate() method to be run whenever the Home screen is created
Not necessarily. If it is already running, it would be called with onNewIntent()
.
If someone could just offer some enlightenment into this matter, the basic question is whether onResume() or onCreate() gets called when I tap the Home button
Any time any activity returns to the foreground from a user input standpoint, onResume()
is called. Home screens should be no different in this regard.
onCreate()
is called when the activity is created. Existing activities are not created, but are merely brought back to the foreground. If what triggered the activity to return to the foreground was a startActivity()
call, the activity will be called with onNewIntent()
and onResume()
(and usually onStart()
, for that matter).
Exactly what I needed, thanks
– mike
Jul 9 '13 at 16:23
add a comment |
When you install application first time following method call one by one in Activity
- onCreate()
- onStart()
- onResume()
after that when you press Home Button then following method call
- onPause()
- onStop()
Note: onDestroy() method not call after press Home Button.
following code for demo purpose. first run your code in Emulator or Device and after that click HOME Button to check result in your console.
package com.example.checkdataversion;
import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
public class MainActivity extends Activity
private static final String TAG = "main";
@Override
protected void onCreate(Bundle savedInstanceState)
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
Log.i(TAG, "oncreate");
setContentView(R.layout.fragment_main);
@Override
protected void onStart()
// TODO Auto-generated method stub
super.onStart();
Log.i(TAG, "onstart");
@Override
protected void onResume()
// TODO Auto-generated method stub
super.onResume();
Log.i(TAG, "onresume");
@Override
protected void onPause()
// TODO Auto-generated method stub
super.onPause();
Log.i(TAG, "onpause");
@Override
protected void onStop()
// TODO Auto-generated method stub
super.onStop();
Log.i(TAG, "onstop");
@Override
protected void onDestroy()
super.onDestroy();
Log.i(TAG, "ondestroy");
add a comment |
Easy, you just have to override onAttachedToWindow()
@Override
public void onAttachedToWindow()
super.onAttachedToWindow();
this.getWindow().setType(WindowManager.LayoutParams.TYPE_KEYGUARD);
And then easily catch home button pressed
@Override
public boolean onKeyDown(int keyCode, KeyEvent event)
if(keyCode == KeyEvent.KEYCODE_HOME)
//do some stuff
);
Take from http://nisha113a5.blogspot.fr/
Hope this help.
3
Applications no longer receive the Home Key press. This is to prevent hijacking the Home key.
– Karakuri
Jul 9 '13 at 16:21
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f17552822%2fwhich-method-is-run-when-home-button-pressed%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
3 Answers
3
active
oldest
votes
3 Answers
3
active
oldest
votes
active
oldest
votes
active
oldest
votes
tapping the Home button creates an intent to launch the Home screen and then starts that intent
Correct.
If this is the case, I'd expect the onCreate() method to be run whenever the Home screen is created
Not necessarily. If it is already running, it would be called with onNewIntent()
.
If someone could just offer some enlightenment into this matter, the basic question is whether onResume() or onCreate() gets called when I tap the Home button
Any time any activity returns to the foreground from a user input standpoint, onResume()
is called. Home screens should be no different in this regard.
onCreate()
is called when the activity is created. Existing activities are not created, but are merely brought back to the foreground. If what triggered the activity to return to the foreground was a startActivity()
call, the activity will be called with onNewIntent()
and onResume()
(and usually onStart()
, for that matter).
Exactly what I needed, thanks
– mike
Jul 9 '13 at 16:23
add a comment |
tapping the Home button creates an intent to launch the Home screen and then starts that intent
Correct.
If this is the case, I'd expect the onCreate() method to be run whenever the Home screen is created
Not necessarily. If it is already running, it would be called with onNewIntent()
.
If someone could just offer some enlightenment into this matter, the basic question is whether onResume() or onCreate() gets called when I tap the Home button
Any time any activity returns to the foreground from a user input standpoint, onResume()
is called. Home screens should be no different in this regard.
onCreate()
is called when the activity is created. Existing activities are not created, but are merely brought back to the foreground. If what triggered the activity to return to the foreground was a startActivity()
call, the activity will be called with onNewIntent()
and onResume()
(and usually onStart()
, for that matter).
Exactly what I needed, thanks
– mike
Jul 9 '13 at 16:23
add a comment |
tapping the Home button creates an intent to launch the Home screen and then starts that intent
Correct.
If this is the case, I'd expect the onCreate() method to be run whenever the Home screen is created
Not necessarily. If it is already running, it would be called with onNewIntent()
.
If someone could just offer some enlightenment into this matter, the basic question is whether onResume() or onCreate() gets called when I tap the Home button
Any time any activity returns to the foreground from a user input standpoint, onResume()
is called. Home screens should be no different in this regard.
onCreate()
is called when the activity is created. Existing activities are not created, but are merely brought back to the foreground. If what triggered the activity to return to the foreground was a startActivity()
call, the activity will be called with onNewIntent()
and onResume()
(and usually onStart()
, for that matter).
tapping the Home button creates an intent to launch the Home screen and then starts that intent
Correct.
If this is the case, I'd expect the onCreate() method to be run whenever the Home screen is created
Not necessarily. If it is already running, it would be called with onNewIntent()
.
If someone could just offer some enlightenment into this matter, the basic question is whether onResume() or onCreate() gets called when I tap the Home button
Any time any activity returns to the foreground from a user input standpoint, onResume()
is called. Home screens should be no different in this regard.
onCreate()
is called when the activity is created. Existing activities are not created, but are merely brought back to the foreground. If what triggered the activity to return to the foreground was a startActivity()
call, the activity will be called with onNewIntent()
and onResume()
(and usually onStart()
, for that matter).
edited Nov 13 '18 at 3:05
Pang
6,8921563101
6,8921563101
answered Jul 9 '13 at 16:00
CommonsWareCommonsWare
766k13818691921
766k13818691921
Exactly what I needed, thanks
– mike
Jul 9 '13 at 16:23
add a comment |
Exactly what I needed, thanks
– mike
Jul 9 '13 at 16:23
Exactly what I needed, thanks
– mike
Jul 9 '13 at 16:23
Exactly what I needed, thanks
– mike
Jul 9 '13 at 16:23
add a comment |
When you install application first time following method call one by one in Activity
- onCreate()
- onStart()
- onResume()
after that when you press Home Button then following method call
- onPause()
- onStop()
Note: onDestroy() method not call after press Home Button.
following code for demo purpose. first run your code in Emulator or Device and after that click HOME Button to check result in your console.
package com.example.checkdataversion;
import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
public class MainActivity extends Activity
private static final String TAG = "main";
@Override
protected void onCreate(Bundle savedInstanceState)
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
Log.i(TAG, "oncreate");
setContentView(R.layout.fragment_main);
@Override
protected void onStart()
// TODO Auto-generated method stub
super.onStart();
Log.i(TAG, "onstart");
@Override
protected void onResume()
// TODO Auto-generated method stub
super.onResume();
Log.i(TAG, "onresume");
@Override
protected void onPause()
// TODO Auto-generated method stub
super.onPause();
Log.i(TAG, "onpause");
@Override
protected void onStop()
// TODO Auto-generated method stub
super.onStop();
Log.i(TAG, "onstop");
@Override
protected void onDestroy()
super.onDestroy();
Log.i(TAG, "ondestroy");
add a comment |
When you install application first time following method call one by one in Activity
- onCreate()
- onStart()
- onResume()
after that when you press Home Button then following method call
- onPause()
- onStop()
Note: onDestroy() method not call after press Home Button.
following code for demo purpose. first run your code in Emulator or Device and after that click HOME Button to check result in your console.
package com.example.checkdataversion;
import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
public class MainActivity extends Activity
private static final String TAG = "main";
@Override
protected void onCreate(Bundle savedInstanceState)
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
Log.i(TAG, "oncreate");
setContentView(R.layout.fragment_main);
@Override
protected void onStart()
// TODO Auto-generated method stub
super.onStart();
Log.i(TAG, "onstart");
@Override
protected void onResume()
// TODO Auto-generated method stub
super.onResume();
Log.i(TAG, "onresume");
@Override
protected void onPause()
// TODO Auto-generated method stub
super.onPause();
Log.i(TAG, "onpause");
@Override
protected void onStop()
// TODO Auto-generated method stub
super.onStop();
Log.i(TAG, "onstop");
@Override
protected void onDestroy()
super.onDestroy();
Log.i(TAG, "ondestroy");
add a comment |
When you install application first time following method call one by one in Activity
- onCreate()
- onStart()
- onResume()
after that when you press Home Button then following method call
- onPause()
- onStop()
Note: onDestroy() method not call after press Home Button.
following code for demo purpose. first run your code in Emulator or Device and after that click HOME Button to check result in your console.
package com.example.checkdataversion;
import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
public class MainActivity extends Activity
private static final String TAG = "main";
@Override
protected void onCreate(Bundle savedInstanceState)
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
Log.i(TAG, "oncreate");
setContentView(R.layout.fragment_main);
@Override
protected void onStart()
// TODO Auto-generated method stub
super.onStart();
Log.i(TAG, "onstart");
@Override
protected void onResume()
// TODO Auto-generated method stub
super.onResume();
Log.i(TAG, "onresume");
@Override
protected void onPause()
// TODO Auto-generated method stub
super.onPause();
Log.i(TAG, "onpause");
@Override
protected void onStop()
// TODO Auto-generated method stub
super.onStop();
Log.i(TAG, "onstop");
@Override
protected void onDestroy()
super.onDestroy();
Log.i(TAG, "ondestroy");
When you install application first time following method call one by one in Activity
- onCreate()
- onStart()
- onResume()
after that when you press Home Button then following method call
- onPause()
- onStop()
Note: onDestroy() method not call after press Home Button.
following code for demo purpose. first run your code in Emulator or Device and after that click HOME Button to check result in your console.
package com.example.checkdataversion;
import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
public class MainActivity extends Activity
private static final String TAG = "main";
@Override
protected void onCreate(Bundle savedInstanceState)
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
Log.i(TAG, "oncreate");
setContentView(R.layout.fragment_main);
@Override
protected void onStart()
// TODO Auto-generated method stub
super.onStart();
Log.i(TAG, "onstart");
@Override
protected void onResume()
// TODO Auto-generated method stub
super.onResume();
Log.i(TAG, "onresume");
@Override
protected void onPause()
// TODO Auto-generated method stub
super.onPause();
Log.i(TAG, "onpause");
@Override
protected void onStop()
// TODO Auto-generated method stub
super.onStop();
Log.i(TAG, "onstop");
@Override
protected void onDestroy()
super.onDestroy();
Log.i(TAG, "ondestroy");
answered Aug 11 '14 at 9:16
vikselnvikseln
33847
33847
add a comment |
add a comment |
Easy, you just have to override onAttachedToWindow()
@Override
public void onAttachedToWindow()
super.onAttachedToWindow();
this.getWindow().setType(WindowManager.LayoutParams.TYPE_KEYGUARD);
And then easily catch home button pressed
@Override
public boolean onKeyDown(int keyCode, KeyEvent event)
if(keyCode == KeyEvent.KEYCODE_HOME)
//do some stuff
);
Take from http://nisha113a5.blogspot.fr/
Hope this help.
3
Applications no longer receive the Home Key press. This is to prevent hijacking the Home key.
– Karakuri
Jul 9 '13 at 16:21
add a comment |
Easy, you just have to override onAttachedToWindow()
@Override
public void onAttachedToWindow()
super.onAttachedToWindow();
this.getWindow().setType(WindowManager.LayoutParams.TYPE_KEYGUARD);
And then easily catch home button pressed
@Override
public boolean onKeyDown(int keyCode, KeyEvent event)
if(keyCode == KeyEvent.KEYCODE_HOME)
//do some stuff
);
Take from http://nisha113a5.blogspot.fr/
Hope this help.
3
Applications no longer receive the Home Key press. This is to prevent hijacking the Home key.
– Karakuri
Jul 9 '13 at 16:21
add a comment |
Easy, you just have to override onAttachedToWindow()
@Override
public void onAttachedToWindow()
super.onAttachedToWindow();
this.getWindow().setType(WindowManager.LayoutParams.TYPE_KEYGUARD);
And then easily catch home button pressed
@Override
public boolean onKeyDown(int keyCode, KeyEvent event)
if(keyCode == KeyEvent.KEYCODE_HOME)
//do some stuff
);
Take from http://nisha113a5.blogspot.fr/
Hope this help.
Easy, you just have to override onAttachedToWindow()
@Override
public void onAttachedToWindow()
super.onAttachedToWindow();
this.getWindow().setType(WindowManager.LayoutParams.TYPE_KEYGUARD);
And then easily catch home button pressed
@Override
public boolean onKeyDown(int keyCode, KeyEvent event)
if(keyCode == KeyEvent.KEYCODE_HOME)
//do some stuff
);
Take from http://nisha113a5.blogspot.fr/
Hope this help.
answered Jul 9 '13 at 16:01
AngudroidAngudroid
80511020
80511020
3
Applications no longer receive the Home Key press. This is to prevent hijacking the Home key.
– Karakuri
Jul 9 '13 at 16:21
add a comment |
3
Applications no longer receive the Home Key press. This is to prevent hijacking the Home key.
– Karakuri
Jul 9 '13 at 16:21
3
3
Applications no longer receive the Home Key press. This is to prevent hijacking the Home key.
– Karakuri
Jul 9 '13 at 16:21
Applications no longer receive the Home Key press. This is to prevent hijacking the Home key.
– Karakuri
Jul 9 '13 at 16:21
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f17552822%2fwhich-method-is-run-when-home-button-pressed%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
developer.android.com/guide/components/…
– Raghunandan
Jul 9 '13 at 15:58
Yeah, when the Home is put in the background, my question is what is called when you tap Home and return to the Home screen
– mike
Jul 9 '13 at 15:58
You may want to override
onBackPressed()
– PatrickNLT
Jul 9 '13 at 16:00