我应用了幻灯片转换,通过活动A转到活动B.
活动A - >活动B
当我回到活动A(通过按下后退按钮)时
活动B - >活动A
然后再次参加活动B
活动A - >活动B
应用程序没有回应。可能的原因及其解决方案是什么?
这是代码: -
活动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);
}
});
}
}
活动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);
}
}
答案 0 :(得分:1)
在onClick()方法内的Activity Anima 中移动捆绑初始化。尝试
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);
}
});