How to switch activity without animation in Android?

You can create a style, <style name=”noAnimTheme” parent=”android:Theme”> <item name=”android:windowAnimationStyle”>@null</item> </style> and set it as theme for your activity in the manifest: <activity android:name=”.ui.ArticlesActivity” android:theme=”@style/noAnimTheme”> </activity> You can also define a style to specify custom entry and exit animations. http://developer.android.com/reference/android/R.attr.html#windowEnterAnimation

Passing a Bundle on startActivity()?

You have a few options: 1) Use the Bundle from the Intent: Intent mIntent = new Intent(this, Example.class); Bundle extras = mIntent.getExtras(); extras.putString(key, value); 2) Create a new Bundle Intent mIntent = new Intent(this, Example.class); Bundle mBundle = new Bundle(); mBundle.putString(key, value); mIntent.putExtras(mBundle); 3) Use the putExtra() shortcut method of the Intent Intent mIntent = … Read more

How can I return to a parent activity correctly?

You declared activity A with the standard launchMode in the Android manifest. According to the documentation, that means the following: The system always creates a new instance of the activity in the target task and routes the intent to it. Therefore, the system is forced to recreate activity A (i.e. calling onCreate) even if the … Read more

Android: How can I get the current foreground activity (from a service)?

Update: this no longer works with other apps’ activities as of Android 5.0 Here’s a good way to do it using the activity manager. You basically get the runningTasks from the activity manager. It will always return the currently active task first. From there you can get the topActivity. Example here There’s an easy way … Read more

Activity transition in Android

Here’s the code to do a nice smooth fade between two Activities.. Create a file called fadein.xml in res/anim <?xml version=”1.0″ encoding=”utf-8″?> <alpha xmlns:android=”http://schemas.android.com/apk/res/android” android:interpolator=”@android:anim/accelerate_interpolator” android:fromAlpha=”0.0″ android:toAlpha=”1.0″ android:duration=”2000″ /> Create a file called fadeout.xml in res/anim <?xml version=”1.0″ encoding=”utf-8″?> <alpha xmlns:android=”http://schemas.android.com/apk/res/android” android:interpolator=”@android:anim/accelerate_interpolator” android:fromAlpha=”1.0″ android:toAlpha=”0.0″ android:duration=”2000″ /> If you want to fade from Activity A to … Read more

Android. Fragment getActivity() sometimes returns null

It seems that I found a solution to my problem. Very good explanations are given here and here. Here is my example: pulic class MyActivity extends FragmentActivity{ private ViewPager pager; private TitlePageIndicator indicator; private TabsAdapter adapter; private Bundle savedInstanceState; @Override public void onCreate(Bundle savedInstanceState) { …. this.savedInstanceState = savedInstanceState; pager = (ViewPager) findViewById(R.id.pager);; indicator = … Read more

How to get current foreground activity context in android?

(Note: An official API was added in API 14: See this answer https://stackoverflow.com/a/29786451/119733) DO NOT USE PREVIOUS (waqas716) answer. You will have memory leak problem, because of the static reference to the activity. For more detail see the following link http://android-developers.blogspot.fr/2009/01/avoiding-memory-leaks.html To avoid this, you should manage activities references. Add the name of the application … Read more

How to pass data from 2nd activity to 1st activity when pressed back? – android

Start Activity2 with startActivityForResult and use setResult method for sending data back from Activity2 to Activity1. In Activity1 you will need to override onActivityResult for updating TextView with EditText data from Activity2. For example: In Activity1, start Activity2 as: Intent i = new Intent(this, Activity2.class); startActivityForResult(i, 1); In Activity2, use setResult for sending data back: … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)