Android jump Activity jump data communication and jump Animation

Source: Internet
Author: User


1. when one ActivityA enters another ActivityB, the wait dialog box is displayed, indicating that the second Activity will be entered. When we press the return key, the ActivityB will be returned to ActiviyA, if ActivityA directly creates a startActivity and the Activity dialog box is still being transferred, we can start the Activity with startActivityForResult. However, the message will be returned to the previous Activity only after the finish method is called in ActivityB, set the returned result in ActivityB and write onActivityResult in ActivityA to get the returned message.

. ActivityA:


1 @ Override
2 public void onClick (View v ){
3 // TODO Auto-generated method stub
4 if (v = bt ){
5 Intent intent = new Intent (this, OtherActivity. class );
6 intent. putExtra ("other", "second page ");
7 startActivityForResult (intent, 0 );
8 // dialog. show ();
9}
10}
11
12 @ Override
13 protected void onActivityResult (int requestCode, int resultCode, Intent data ){
14 // TODO Auto-generated method stub
15 super. onActivityResult (requestCode, resultCode, data); // Request Code, result code
16 if (resultCode = Activity. RESULT_ OK ){
17 Log. e ("MainActivity", "onActivityResult ");
18 dialog. dismiss ();
19}
20}

 

ActivityB:

SetResult (RESULT_ OK );

 

2. this is slow to enter another Activity, especially when MapActivity loads a map. In the onCreate method, a dialog box is displayed after super () is called, and the dialog box is closed in the callback of view loading, in onWindowFocusChange (), dismisDialog seems useless. It is still being transferred. When the show dialog box is displayed, the View is being loaded.

Protected void onCreate (Bundle savedInstanceState ){
// TODO Auto-generated method stub
Super. onCreate (savedInstanceState );
Dialog = new ProgressDialog (this );
Dialog. show ();

@ Override
Public void onWindowFocusChanged (boolean hasFocus ){
// TODO Auto-generated method stub
Super. onWindowFocusChanged (hasFocus );
If (hasFocus ){
// Dialog. dismiss ();
Log. e ("OtherActivity", "loaded ");
} Else {
Log. e ("OtherActivity", "loading ..");
}

Failed.

3. By the way, the Activity jump animation can be applied under the Application node to apply the animation effect. This allows all the activities to apply the animation subject, or apply the animation to a single Activity. Create a Style file and set windowAnimationStyle to a written Animation Style. The real Animation Style should inherit the Animation. Activity, and then set a unique Animation in each Animation item.

 

Style:


<? Xml version = "1.0" encoding = "UTF-8"?>
<Resources>
<Style name = "ThemeActivity" mce_bogus = "1">
<Item name = "android: windowAnimationStyle"> @ style/AnimationActivity </item>
<Item name = "android: windowNoTitle"> false </item>
</Style>

<Style name = "AnimationActivity" parent = "@ android: style/Animation. Activity" mce_bogus = "1">

<-Entering an Acitvity consists of two parts. The current Activity exits from the animation, and the next Activity enters the animation.->
<Item name = "android: activityOpenEnterAnimation"> @ anim/enter_out </item> // enter the animation for the next Activty.
<Item name = "android: activityOpenExitAnimation"> @ anim/enter_in </item> // animation for exiting the current Activity

<-The previous Activity contains two parts. The current Activity destroys the animation and the previous Activity enters the animation.->
<Item name = "android: activityCloseEnterAnimation"> @ anim/in </item> // enter the animation for the previous Activity
<Item name = "android: activityCloseExitAnimation"> @ anim/out </item> // exit animation of the current Activity

</Style>

</Resources>

 

Here is the animation I defined:

Go to the next Activity. The current Activity exits from the screen to the left, and the next Activity rises from the bottom to the top of the screen. The effect of the return Activity is similar to that of the Hujiang application. The current Activity is scaled down to the right side, the transparency is reduced from having to having, and the previous Activity is scaled from 1.5 times to the normal size, however, it scales with the center in the upper left corner.

 

Open:

Current Acitivity destroy Animation


<? Xml version = "1.0" encoding = "UTF-8"?>
<Set xmlns: android = "http://schemas.android.com/apk/res/android">
<Translate android: fromXDelta = "0"
Android: toXDelta = "-400"
Android: duration = "500" type = "codeph" text = "/codeph"/> // here is the screen animation for the view to be removed from the right to the left

& Lt; alpha android: fromAlpha = "1.0"
Android: toAlpha = "0.5"
Android: duration = "800"/>

</Set>

The next Acitivity enters the animation.


<? Xml version = "1.0" encoding = "UTF-8"?>
<Set xmlns: android = "http://schemas.android.com/apk/res/android">

<Translate android: fromYDelta = "800"
Android: toYDelta = "0"
Android: duration = "500"/> // The animation is raised from the bottom.

& Lt; alpha android: fromAlpha = "0.1"
Android: toAlpha = "1.0"
Android: duration = "800"/>

</Set>

 

Close:

 

Animation destruction for the current Activity


<? Xml version = "1.0" encoding = "UTF-8"?>
<Set xmlns: android = "http://schemas.android.com/apk/res/android">
<Scale android: fromXScale = "1.0"
Android: toXScale = "0.5"
Android: fromYScale = "1.0"
Android: toYScale = "0.5"
Android: Required Tx = "75%"
Android: Ty = "50%"
Android: duration= "800"
Android: interpolator = "@ android: anim/accelerate_interpolator"/> // zoom to the right of the screen

& Lt; alpha android: fromAlpha = "1.0"
Android: toAlpha = "0.1"
Android: duration = "800"/>

</Set>

 

The last Actiivty enters the animation.

 


<? Xml version = "1.0" encoding = "UTF-8"?>
<Set xmlns: android = "http://schemas.android.com/apk/res/android">

<Scale android: fromXScale = "1.5"
Android: toXScale = "1.0"
Android: fromYScale = "1.5"
Android: toYScale = "1.0"
Android: duration= "800"
Android: Required Tx = "100%"
Android: Ty = "100%"/> // zoom in the upper left corner

</Set>

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.