• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Apps Oncreate function

cinojose

Lurker
Guys, i got two activities in my app. in one they are downloading content from a web resource, the other activity is just the details about an item of activity 1 , so once i go to my activity 1 from my activity 2 , the oncrete method is still invoking.?how to make the oncreate to be just invoked only once i created the activity?
 
Dear Sirs and Madams,

I've had same problem (onCreate is called more than once), but in just one actvity. It occurs when phone is rotated. Is it normal? Can onCreate be called more than once in same activity?

Bellow, a simple test I've made to confirm it. There is just a button with id=button1 created via eclipse IDE. Every time I rotate phone, text of button returns to "123".

Source code:

package toc.p;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;

public class ToncreatActivity extends Activity {

Button b1;

/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);

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

b1.setText( "123" );

b1.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
b1.setText( "abc" );
}
});
}
}


The layout.xml:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >

<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/hello" />

<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button" />

</LinearLayout>
 
Back
Top Bottom