Reputation: 377
I applied slide transition to move to Activity B through Activity A
Activity A -> Activity B
When i go back to Activity A (By Pressing Back Button)
Activity B -> Activity A
and then again to Activity B
Activity A -> Activity B
App does not respond. What can be possible reason and its solution?
Here is code:-
Activity A:-
package com.tester;
import android.annotation.SuppressLint;
import android.app.ActivityOptions;
import android.content.Intent;
import android.graphics.Typeface;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.transition.Scene;
import android.transition.Slide;
import android.transition.TransitionManager;
import android.view.Gravity;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;
public class Anima extends AppCompatActivity {
ViewGroup root_scene;
Bundle bundle;
@SuppressLint("NewApi")
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.anima);
root_scene = (ViewGroup) findViewById(R.id.root_scene);
ImageView iv = (ImageView) findViewById(R.id.info_image);
/*final Slide slide = new Slide(Gravity.TOP);
slide.addTarget(R.id.test_image);
getWindow().setEnterTransition(slide);
*/
bundle = ActivityOptions.makeSceneTransitionAnimation(this).toBundle();
TextView tv = (TextView) findViewById(R.id.head);
Typeface type = Typeface.createFromAsset(getAssets(), "roboto.ttf");
tv.setTypeface(type);
tv.setText("Armed robbers used Pokémon Go to target victims in Missouri");
iv.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
Intent intent = new Intent(Anima.this,Second.class);
startActivity(intent,bundle);
}
});
}
}
Activity B:-
import android.annotation.SuppressLint;
import android.app.ActivityOptions;
import android.content.Intent;
import android.graphics.Typeface;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.transition.Slide;
import android.view.Gravity;
import android.widget.TextView;
public class Second extends AppCompatActivity{
Bundle bundle;
@SuppressLint("NewApi")
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.another_scene);
bundle = ActivityOptions.makeSceneTransitionAnimation(this).toBundle();
TextView tv2 = (TextView) findViewById(R.id.details);
Typeface type = Typeface.createFromAsset(getAssets(), "robot_light.ttf");
tv2.setTypeface(type);
tv2.setText("As popular as Pokémon Go has become, that it sends players out into the real world to find Pokémon is creating new, unexpected problems. The O'Fallon, Missouri Police Department reported on Facebook today that armed robbers have used the app to lure victims in and rob them at gunpoint.\nThe police received reports about the robberies and were able to apprehend four suspects in the area. Apparently, the thieves used the app to set up a beacon at a Pokéstop within the game. Using this method, Sergeant Bill Stringer of the OPD told Motherboard that the culprits were able to rob 11 players, all between the ages of 16 and 18, in the St. Louis and St. Charles counties of Missouri.");
Slide slide = new Slide(Gravity.BOTTOM);
slide.addTarget(tv2);
getWindow().setEnterTransition(slide);
}
}
Upvotes: 1
Views: 55
Reputation: 3455
Move your bundle initialization in Activity Anima inside the onClick() method. Try
iv.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
bundle = ActivityOptions.makeSceneTransitionAnimation(Anima.this).toBundle();
Intent intent = new Intent(Anima.this,Second.class);
startActivity(intent,bundle);
}
});
Upvotes: 1