Hi,

I am still facing this issue.  I am not sure how to refresh my previous
activity on back button.  I had written the code of calling the intent
itself of onResume() method but everytime i am press back button of next
activity it goes to the previous activity's on resume method and reload that
activity.  And then when i click back button from there it calls that
activity from which i loaded it.

*Scenario is:

1)  Activity 1 - > Activity 2
2) From Activity 2 called back button
3) It goes onresume method of activity 1 and reloaded it.
4) When I click back button on activity 1 it goes to the activity 2.
5) Now, clicked back button on activity 2
6) It reloaded activity 1 by going into on resume method of it.
*
This loop continues till infinity and it never goes back to the home screen.

Any suggetions would be a great help as I need it on urgent basis !!

Thanks!!

On Wed, Mar 23, 2011 at 1:07 PM, Nick Kulikaev <[email protected]> wrote:

> Hi, here is a very simple and stupid example:
> public class MainActivity extends Activity {
>  private TextView mText;
> private boolean mTextSwitcherFlag;
>  OnClickListener mRefreshButtonListener = new OnClickListener() {
>
> @Override
> public void onClick(View v) {
> refreshContent();
> }
>  };
>  OnClickListener mStartActivityButtonListener = new OnClickListener() {
>
> @Override
> public void onClick(View v) {
> startActivity();
> }
>  };
>
> @Override
> protected void onCreate(Bundle savedInstanceState) {
> super.onCreate(savedInstanceState);
> setContentView(R.layout.body);
>  mTextSwitcherFlag = true;
> mText = (TextView)findViewById(R.id.text);
>  Button refreshContentButton =
> (Button)findViewById(R.id.refresh_content_button);
> Button startActivityButton =
> (Button)findViewById(R.id.start_activity_button);
>  refreshContentButton.setOnClickListener(mRefreshButtonListener);
> startActivityButton.setOnClickListener(mStartActivityButtonListener);
> }
>
> private void refreshContent() {
> if (mText != null) {
> if (mTextSwitcherFlag) {
> mText.setText(R.string.text_one);
> } else {
> mText.setText(R.string.text_two);
> }
> mTextSwitcherFlag = !mTextSwitcherFlag;
> }
> }
>  private void startActivity() {
> Intent i = new Intent(getBaseContext(), SecondaryActivity.class);
> startActivity(i);
> }
>
> @Override
> protected void onResume() {
> super.onResume();
> refreshContent();
> }
>
> }
>
> Every time you click on refresh button it updates text on the screen.
> Secondary activity could be whatever you have, i just wanted to show you how
> you can use onResume method to refresh content when you go back from
> secondary activity. I attached the whole working example.
>
> Cheers,
> Nick
>
>

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to