OnResume Methods are not executing on launching new activity using startActivity(intent)











up vote
-1
down vote

favorite












Suppose i have activity 'A' which is showing data fetched from online database say Number of questions attended.



User goes from Activity 'A' -> 'B' where he attended the questions and comes back to Activity 'A' after pressing 'back' button.



Inside Activity 'A' I have methods executing correctly, fetching data online and updating the TextViews, Which i am calling in from onResume() method..



Now problem is when i go back from Activity 'B' to Activity 'A', onResume is not executing and those methods are not executing..



When i click power button and put the screen on sleep and awake the screen, data is getting updated correctly.



I know the Lifecycle it says that onResume will execute.



I am simply using the below code for going back from 'B' -> 'A'



backProfileImgView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
finish();
startActivity(new Intent(getApplicationContext(),ProfileActivity.class));

}
});


and Activity 'A' is having onResume() method as



public void onResume() {
super.onResume();
setContentView(R.layout.activity_profile);
new GetContacts().execute();
updateAllViews();
pDialog.dismiss();
}


But i dont know where i am doing wrong. Please advise










share|improve this question


















  • 1




    your ques is very unclear, please replace A, B with real activity name
    – Touhidul Islam
    Nov 11 at 10:28












  • I think you must add Activity A and B code or just told me the names im confused
    – Radesh
    Nov 11 at 10:48















up vote
-1
down vote

favorite












Suppose i have activity 'A' which is showing data fetched from online database say Number of questions attended.



User goes from Activity 'A' -> 'B' where he attended the questions and comes back to Activity 'A' after pressing 'back' button.



Inside Activity 'A' I have methods executing correctly, fetching data online and updating the TextViews, Which i am calling in from onResume() method..



Now problem is when i go back from Activity 'B' to Activity 'A', onResume is not executing and those methods are not executing..



When i click power button and put the screen on sleep and awake the screen, data is getting updated correctly.



I know the Lifecycle it says that onResume will execute.



I am simply using the below code for going back from 'B' -> 'A'



backProfileImgView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
finish();
startActivity(new Intent(getApplicationContext(),ProfileActivity.class));

}
});


and Activity 'A' is having onResume() method as



public void onResume() {
super.onResume();
setContentView(R.layout.activity_profile);
new GetContacts().execute();
updateAllViews();
pDialog.dismiss();
}


But i dont know where i am doing wrong. Please advise










share|improve this question


















  • 1




    your ques is very unclear, please replace A, B with real activity name
    – Touhidul Islam
    Nov 11 at 10:28












  • I think you must add Activity A and B code or just told me the names im confused
    – Radesh
    Nov 11 at 10:48













up vote
-1
down vote

favorite









up vote
-1
down vote

favorite











Suppose i have activity 'A' which is showing data fetched from online database say Number of questions attended.



User goes from Activity 'A' -> 'B' where he attended the questions and comes back to Activity 'A' after pressing 'back' button.



Inside Activity 'A' I have methods executing correctly, fetching data online and updating the TextViews, Which i am calling in from onResume() method..



Now problem is when i go back from Activity 'B' to Activity 'A', onResume is not executing and those methods are not executing..



When i click power button and put the screen on sleep and awake the screen, data is getting updated correctly.



I know the Lifecycle it says that onResume will execute.



I am simply using the below code for going back from 'B' -> 'A'



backProfileImgView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
finish();
startActivity(new Intent(getApplicationContext(),ProfileActivity.class));

}
});


and Activity 'A' is having onResume() method as



public void onResume() {
super.onResume();
setContentView(R.layout.activity_profile);
new GetContacts().execute();
updateAllViews();
pDialog.dismiss();
}


But i dont know where i am doing wrong. Please advise










share|improve this question













Suppose i have activity 'A' which is showing data fetched from online database say Number of questions attended.



User goes from Activity 'A' -> 'B' where he attended the questions and comes back to Activity 'A' after pressing 'back' button.



Inside Activity 'A' I have methods executing correctly, fetching data online and updating the TextViews, Which i am calling in from onResume() method..



Now problem is when i go back from Activity 'B' to Activity 'A', onResume is not executing and those methods are not executing..



When i click power button and put the screen on sleep and awake the screen, data is getting updated correctly.



I know the Lifecycle it says that onResume will execute.



I am simply using the below code for going back from 'B' -> 'A'



backProfileImgView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
finish();
startActivity(new Intent(getApplicationContext(),ProfileActivity.class));

}
});


and Activity 'A' is having onResume() method as



public void onResume() {
super.onResume();
setContentView(R.layout.activity_profile);
new GetContacts().execute();
updateAllViews();
pDialog.dismiss();
}


But i dont know where i am doing wrong. Please advise







android






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 11 at 10:04









amulbhatia

216




216








  • 1




    your ques is very unclear, please replace A, B with real activity name
    – Touhidul Islam
    Nov 11 at 10:28












  • I think you must add Activity A and B code or just told me the names im confused
    – Radesh
    Nov 11 at 10:48














  • 1




    your ques is very unclear, please replace A, B with real activity name
    – Touhidul Islam
    Nov 11 at 10:28












  • I think you must add Activity A and B code or just told me the names im confused
    – Radesh
    Nov 11 at 10:48








1




1




your ques is very unclear, please replace A, B with real activity name
– Touhidul Islam
Nov 11 at 10:28






your ques is very unclear, please replace A, B with real activity name
– Touhidul Islam
Nov 11 at 10:28














I think you must add Activity A and B code or just told me the names im confused
– Radesh
Nov 11 at 10:48




I think you must add Activity A and B code or just told me the names im confused
– Radesh
Nov 11 at 10:48












1 Answer
1






active

oldest

votes

















up vote
2
down vote



accepted










do not call finish() use this



backProfileImgView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
//call only onBackPressed
onBackPressed();
}
});





share|improve this answer























  • Not working, finish() will destroy the current activity i.e. 'B' but my data is not populating in 'A', which is not getting refreshed while coming back from B to A
    – amulbhatia
    Nov 11 at 10:17










  • @amulbhatia your A activity is ProfileActivity and your B activity is ... ??
    – Radesh
    Nov 11 at 10:19










  • @amulbhatia check edited code
    – Radesh
    Nov 11 at 10:25












  • Activity B is showing list of questions.. in recyclerview (Still not working after using onBackPressed)
    – amulbhatia
    Nov 11 at 10:43











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',
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
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53247625%2fonresume-methods-are-not-executing-on-launching-new-activity-using-startactivity%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes








up vote
2
down vote



accepted










do not call finish() use this



backProfileImgView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
//call only onBackPressed
onBackPressed();
}
});





share|improve this answer























  • Not working, finish() will destroy the current activity i.e. 'B' but my data is not populating in 'A', which is not getting refreshed while coming back from B to A
    – amulbhatia
    Nov 11 at 10:17










  • @amulbhatia your A activity is ProfileActivity and your B activity is ... ??
    – Radesh
    Nov 11 at 10:19










  • @amulbhatia check edited code
    – Radesh
    Nov 11 at 10:25












  • Activity B is showing list of questions.. in recyclerview (Still not working after using onBackPressed)
    – amulbhatia
    Nov 11 at 10:43















up vote
2
down vote



accepted










do not call finish() use this



backProfileImgView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
//call only onBackPressed
onBackPressed();
}
});





share|improve this answer























  • Not working, finish() will destroy the current activity i.e. 'B' but my data is not populating in 'A', which is not getting refreshed while coming back from B to A
    – amulbhatia
    Nov 11 at 10:17










  • @amulbhatia your A activity is ProfileActivity and your B activity is ... ??
    – Radesh
    Nov 11 at 10:19










  • @amulbhatia check edited code
    – Radesh
    Nov 11 at 10:25












  • Activity B is showing list of questions.. in recyclerview (Still not working after using onBackPressed)
    – amulbhatia
    Nov 11 at 10:43













up vote
2
down vote



accepted







up vote
2
down vote



accepted






do not call finish() use this



backProfileImgView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
//call only onBackPressed
onBackPressed();
}
});





share|improve this answer














do not call finish() use this



backProfileImgView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
//call only onBackPressed
onBackPressed();
}
});






share|improve this answer














share|improve this answer



share|improve this answer








edited Nov 11 at 10:24

























answered Nov 11 at 10:10









Radesh

2,71411229




2,71411229












  • Not working, finish() will destroy the current activity i.e. 'B' but my data is not populating in 'A', which is not getting refreshed while coming back from B to A
    – amulbhatia
    Nov 11 at 10:17










  • @amulbhatia your A activity is ProfileActivity and your B activity is ... ??
    – Radesh
    Nov 11 at 10:19










  • @amulbhatia check edited code
    – Radesh
    Nov 11 at 10:25












  • Activity B is showing list of questions.. in recyclerview (Still not working after using onBackPressed)
    – amulbhatia
    Nov 11 at 10:43


















  • Not working, finish() will destroy the current activity i.e. 'B' but my data is not populating in 'A', which is not getting refreshed while coming back from B to A
    – amulbhatia
    Nov 11 at 10:17










  • @amulbhatia your A activity is ProfileActivity and your B activity is ... ??
    – Radesh
    Nov 11 at 10:19










  • @amulbhatia check edited code
    – Radesh
    Nov 11 at 10:25












  • Activity B is showing list of questions.. in recyclerview (Still not working after using onBackPressed)
    – amulbhatia
    Nov 11 at 10:43
















Not working, finish() will destroy the current activity i.e. 'B' but my data is not populating in 'A', which is not getting refreshed while coming back from B to A
– amulbhatia
Nov 11 at 10:17




Not working, finish() will destroy the current activity i.e. 'B' but my data is not populating in 'A', which is not getting refreshed while coming back from B to A
– amulbhatia
Nov 11 at 10:17












@amulbhatia your A activity is ProfileActivity and your B activity is ... ??
– Radesh
Nov 11 at 10:19




@amulbhatia your A activity is ProfileActivity and your B activity is ... ??
– Radesh
Nov 11 at 10:19












@amulbhatia check edited code
– Radesh
Nov 11 at 10:25






@amulbhatia check edited code
– Radesh
Nov 11 at 10:25














Activity B is showing list of questions.. in recyclerview (Still not working after using onBackPressed)
– amulbhatia
Nov 11 at 10:43




Activity B is showing list of questions.. in recyclerview (Still not working after using onBackPressed)
– amulbhatia
Nov 11 at 10:43


















draft saved

draft discarded




















































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.





Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


Please pay close attention to the following guidance:


  • 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.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53247625%2fonresume-methods-are-not-executing-on-launching-new-activity-using-startactivity%23new-answer', 'question_page');
}
);

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







Popular posts from this blog

Xamarin.iOS Cant Deploy on Iphone

Glorious Revolution

Dulmage-Mendelsohn matrix decomposition in Python