In my application, I want to transit from Fragment to Activity.
For this purpose I am using following code for Animation,
Bundle bndlanimation =ActivityOptions.makeCustomAnimation(getActivity(), R.anim.slideinleft,R.anim.slideinright).toBundle();
startActivity(intentonboard,bndlanimation);
This works fine.
But What I want to do is that, I am moving from Fragment To Activity.
So I just want to apply the exit animation for Fragment only. Next Activity should be added behind the scene without animation.
So What Should I write in place of enter animation ?
I tried with 0 instead of R.anim.slideinright. But It effects on Exit animation.
Thanks
if you in fragment Layout and wanna to get intent to same activity you must use this...
Intent intent = new Intent(getActivity(),MainActivty.class);
startActivity(intent);
getActivity().overridePendingTransition(android.R.anim.fade_in, android.R.anim.fade_out);
getActivity().overridePendingTransition(R.animator.slide_in_from_left, R.animator.slide_in_from_right);
Use getActivity() After startActivity(intent);
May this help you.
Related
I have an activity I animate to with a transition animation, like this:
ActivityOptionsCompat options = ActivityOptionsCompat.makeSceneTransitionAnimation(activity, view, transitionStr);
ActivityCompat.startActivity(activity, intent, options.toBundle());
However, when I go back, I don't want the animation to run in inverse. Is that possible? I'm using AppCompatActivity from appcompat-v7:23.1.1.
If you never want to have that transition back to the parent activity, use
finish();
You can wrap it around a condition if you sometimes want to the transition on the way back to the parent activity. An example use case would be to disable the transition when an interstitial ad was displayed:
if (interstitialAdWasDisplayed) {
finish();
} else {
finishAfterTransition();
}
A possible duplicate of Overriding Transition
finish();
Details.this.overridePendingTransition(R.anim.nothing,R.anim.nothing);
With this piece of code, you can override the finish animation of the current activity.
According to the answers to this question you can't run an animation in inverse. Instead I would create another transition which is basically the inverse of the transition you use when you start the activity and add it to the Activity like this (R.anim.inverseTransition is the Transition you created):
finish();
Details.this.overridePendingTransition(R.anim.inverseTransition,R.anim.inverseTransition);
(see this answer for more information)
This is my first week of Android development and I am having some troubles so please be patient with me.
This is really simple but all other answers weren't clear or detailed enough for me to apply it.
I am trying to switch from my "activity_main.xml" to a second .xml after a button click. I have already connected the button and put in setContentView(R.layout.view) and it works but I want it to animate. I want the view to come from the right and then the opposite when the user press back. I am doing this in eclipse if that helps.
Thanks in advance!
Assuming what you're after is a transition between two activities, here's what you're going to need to do:
Create a new Activity class. For this example, lets name it MySecondActivity.
In this new Activity class, make sure you're inflating the new layout xml.
In the original Activity class, open the new Activity with an Intent, then on the new activity, call the overridePendingTransition with the animation you want:
Code sample:
Intent intent = new Intent(this, MySecondActivity.class);
startActivity(intent);
getActivity().overridePendingTransition(android.R.anim.slide_in_left, android.R.anim.slide_out_right);
In this example, I'm using Android pre-defined animations. You can create your own too, but I feel this might be enough for your needs.
Hope this helps.
Is there any way to override the pending transition by passing it actual Animation object instead of an ID to an animation resource?
From
startActivity(intent);
overridePendingTransition(R.anim.fadein, R.anim.fadeout);
To
startActivity(intent);
overridePendingTransition(new MyFadeInAnimation(), new MyFadeOutAnimation());
If not, is there a way for me to manually register an animation resource (and attain an ID) programatically?
I really do not want to define the activity transition animations as XML for other reasons.
So one way to do this is to use Fragments. Set overridePendingTransition(0,0); for the Activity. and then in the Fragment, override onCreateAnimator() or if using the old animations, use android.support.v4.app.Fragment and override onCreateAnimation().
Hi All I want to open the "Text-To-Speech output" fragment of Settings from my application. I think first I need to open the settings activity and then its fragment. I tried setting the ComponentName but it was unable to locate the activity.
Should I use FragmentManager; I couldn't find anything specific to my needs. Can somebody give me some link which might explain it well.
You are right, First You need to start the Activity than set the current Fragment in FragmentPager / Manager... Their is no such way to start some foreign fragment from your Activity that would be dangerous see that will lead to zombie fragments floating around the App (or May be I am not aware of that..)
You call the Activity Intent with some parameter for the Fragment name, you want to start i.e. interger, boolean etc...
Intent intent = new Intent(this,SecondActivity.class);
intent.putExtra("fragmentNumber",1); //for example
startActivity(intent);
You check the passed value inside OnCreate of the Second Acitivty and set the desired fragment on top.. inside OnCreate
if(getIntent().getIntExtra("fragmentNumber",0)==1){
//set the desired fragment as current fragment to fragment pager
}
However, I am not getting the problem "It was unable to locate the activity." Have you entered the Activity in manifest file than what was the problem you were facing? Please post the full stack trace.
You can use the following:
Intent ttsSettings = new Intent("com.android.settings.TTS_SETTINGS");
ttsSettings.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(ttsSettings);
There are 4 Tabs in a TabHost, let them be A, B, C, and D. Now each one is just an index page and clicking on any of them shows a different activity.
The problem is that I need to start another activity when the user selects something from the content displayed in the tab. The other activity should also be displayed in the parent tab itself. Is it possible? Or will I have to try something else?
Try this, found this solution in android cookbook,
http://androidcookbook.com/Recipe.seam;jsessionid=5424397F3130CE7769FF47DD67742911?recipeId=1693&recipeFrom=ViewTOC
Can't you change the contentView of your tab instead of starting a new Activity ?
Maybe I'm wrong but I think also that starting an activity in a tab isn't possible because the TabView is hosted in a activity and not the opposite (Tabview don't host an activity per Tab).
I think the common consensus is that it is best not to use individual Activities as tab content due to these limitations. See these questions and answers for pointers to alternatives:
Android: Why shouldn't I use activities inside tabs?
Android - Tabs, MapView, activities within tabs
To summarize the link that Rukmal Dias provided. Here's what you do:
Change your current Activity (that's in a tab) to derive from ActivityGroup
Create a new intent for the Activity you want to switch to
Copy/Paste and call this function in your current activity where "id" is the "android:id" for the layout of the new activity you want to switch to
public void replaceContentView(String id, Intent newIntent){
View view = getLocalActivityManager().startActivity(id,newIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP)) .getDecorView();
this.setContentView(view);}
Here's an example of how I make the call to switch views from my current Tabbed Activity:
public void switchToNextActivity(View view)
{
Intent myIntent = new Intent(getApplicationContext(), MyNextActivity.class);
replaceContentView("next_activity", myIntent);
}
It looses the view hierarchy. When you press the back button, in my case, the app closes.