Reputation: 4595
Hi and thanks for your help.
I want to animate the transition between two activities, but so far without success...
Activity A launches activity B via strartActivity();
In onCreate() of activity B I put the following code:
super.onCreate(savedInstanceState);
overridePendingTransition(R.anim.in,R.anim.out);
setContentView(R.layout.activity_main);
EDIT EDIT:
After suggestions I changed removed the above code and added in the Activity A (that starts Activity B)
public class MainActivity extends Activity {
public DataBaseHelper db;
public EditText enter;
public TextView tv;
public ArrayList<String> listWord;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
db = new DataBaseHelper(this);
try {
db.createDataBase();
} catch (IOException ioe) {
throw new Error("Unable to create database");
}
try {
db.openDataBase();
Log.e("", "database aperto");
} catch (SQLException sqle) {
throw sqle;
}
Cursor constantsCursor = db.getReadableDatabase().rawQuery(
"SELECT _id, korean FROM data ", null);
enter = (EditText) findViewById(R.id.editText1);
Button bn = (Button) findViewById(R.id.button1);
tv = (TextView) findViewById(R.id.textView1);
bn.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
Intent in = new Intent(getApplicationContext(),
SecondActivity.class);
startActivity(in);
overridePendingTransition(android.R.anim.slide_in_left,android.R.anim.slide_out_right);
}
});
}
Again no animation happens...
I would expect an animation to happen when the Activity B starts, but nothing happens
Thre are my R.anim.in and R.anim.out.
R.anim.in
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:zAdjustment="top" >
<rotate
android:duration="2000"
android:fromDegrees="-45"
android:pivotX="50%"
android:pivotY="50%"
android:toDegrees="0"
/>
</set>
R.anim.out
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android" >
<rotate
android:duration="2000"
android:fromDegrees="0"
android:pivotX="50%"
android:pivotY="50%"
android:toDegrees="-45"
/>
</set>
Thank you in advance for your help!!
Upvotes: 0
Views: 506
Reputation: 7533
In Activity
A, where you launch Activity
B, you have to call overridePendingTransition
after startActivity
call.
Code in Activity
A -
Intent i = new Intent(A.this, B.class);
i.putExtras(...);
i.setFlags(...);
startActivity(i);
overridePendingTransition(R.anim.in, R.anim.out);
Upvotes: 1
Reputation: 24720
call overridePendingTransition after calling startActivity:
startActivity(intent);
overridePendingTransition(...)
Upvotes: 2