Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8613145
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T04:48:01+00:00 2026-06-12T04:48:01+00:00

I am a begginer in android. I have a simple code, where I am

  • 0

I am a begginer in android. I have a simple code, where I am calling one activity from my 1st activity and in that 2nd activity I have a button on press of which 2nd activity is finished and 1st activity comes up. Is there any way to call the onCreate method in the 1st activity as the onCreate method is never called in the 1st activity(onResume is called always)? Do i have edit some thing in the manifest file.

Following is my Code

 public class Activity1 extends Activity {
  /** Called when the activity is first created. */

 TextView mTextView ;

 Button b1;
 static int count=0;

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);



    mTextView = (TextView) findViewById(R.id.textView2);

    if (savedInstanceState == null) {
        mTextView.setText("Welcome to HelloAndroid!");
    } else {
        mTextView.setText("Welcome Back!");
        System.out.println("count------>"+ count);
    }



    final Intent i = new Intent(this,activity2.class);
    b1 = (Button) findViewById(R.id.button1);
    b1.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {

            startActivity(i);

        }
    });

}


@Override
public void onResume() 
{
    super.onResume();
    System.out.println("inside Resume");
 }

@Override
public void onConfigurationChanged(Configuration newConfig) {
    super.onConfigurationChanged(newConfig);

    // Checks the orientation of the screen
    if (newConfig.orientation == Configuration.ORIENTATION_LANDSCAPE) {
        Toast.makeText(this, "landscape", Toast.LENGTH_SHORT).show();
    } else if (newConfig.orientation == Configuration.ORIENTATION_PORTRAIT){
        Toast.makeText(this, "portrait", Toast.LENGTH_SHORT).show();
    }
}
    @Override
    public void onSaveInstanceState(Bundle savedInstanceState) {
      super.onSaveInstanceState(savedInstanceState);

      savedInstanceState.putBoolean("MyBoolean", true);
      savedInstanceState.putDouble("myDouble", 1.9);
      savedInstanceState.putInt("MyInt", 1);
      savedInstanceState.putString("MyString", "Welcome back to Android");
      count++;
    }


    @Override
    public void onRestoreInstanceState(Bundle savedInstanceState) {
      super.onRestoreInstanceState(savedInstanceState);

      boolean myBoolean = savedInstanceState.getBoolean("MyBoolean");
      double myDouble = savedInstanceState.getDouble("myDouble");

      System.out.println("MyBoolean"+ myBoolean);
      System.out.println("myDouble"+ myDouble);
    }


}

and here is my 2nd activity which is called by the 1st activiy

public class activity2 extends Activity{

TextView textview;
Button b1;
 public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main2);

        textview = (TextView) findViewById(R.id.textView1);

        textview.setText("in activity2");

        b1 = (Button) findViewById(R.id.button1);

        b1.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {

                finish();
            }
        });
 }
}

Some one please help me
Thanks!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T04:48:02+00:00Added an answer on June 12, 2026 at 4:48 am

    In first Activity,call finish() after startActivity(i); and in second Activity,start first Activity before calling finish().When you start an Activity that has not instance,it’s onCreate will be called.

    Edit:

    If you want to save state of first Activity,you can create a bundle and add state of your views to it.Then add this bundle as extra to intent that starts second Activity.In second Activity get this extra from intent and when you want to start first Activity via intent(for example startFirstActivity intent) add that bundle to this intent(startFirstActivity intent).Now in onCreate method of first Activity,get bundle from intent(via getIntent().getextras()) and if it was not null,extract state of your views from it and set your views states after find them by ID.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am a begginer in android,here I have activity that use web service: SoapObject
Begginer to Android development. I am developing a application, which have three different tabs.
I beginer programmer,and don't have any QA experience (only simple test that i write
i am begginer to jquery and have a simple problem.. I want to make
Hi i'm a c# begginer and i'd like to do a simple program which
i am begginer in android. In my app i am having textview which has
I`m quite begginer at WPF. I have checkBox and I want that every check
I'm C++ begginer. I did this excercise from Deitel's book: Use a one-dimensional array
i have a basic function which requires serializing in my android app. The user
Begginer android programer, I want add and remove item from String list when user

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.