Skip to main content

Android Activities

This post contain my all activity related snippet.



#Start new Activity
staring a new activity is very simple. create an intent and pass that intent to startActivity


1
2
Intent i = new Intent(getBaseContext(), ConverterActivity.class);
                startActivity(i);

#Changing Title
set android:label attribute in the activity element


1
2
3
4
5
6
7
<activity android:name=".AboutActivity"
            android:label="About">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

            </intent-filter>
        </activity>

#Close one Activity when switching to other
It is need when you want your previous activity should close when new one is opened

Add "android:noHistory="true"" to activity in activity element


<activity android:name="skd.app.currencyconverter.MainActivity"    android:label="Currency Converter"    android:noHistory="true">



# Android disable the BackButton
Some time it is need to disable the back button press on the activity to do this you simply needed to override the onBackPressed() methods on your activity



public class Correct_answer extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_correct_answer);



    }

    //just override this and comment the super method
    @Override
    public void onBackPressed() {
       // super.onBackPressed();
    }
}

# Close current activity
just need to call method finish()


this.finish();


Comments

Popular posts from this blog

Xamarin : Simple Calculator Tutorial Visual Studio C#

Simple Calculator in Android (Xamarin) using VisualStudio C#In Brief: This article will help you on building a simple calculator in android Xamarin with simple steps using C# Language in Visual Studio. Detail:
Building this simple calculator will let you learn how to work with the Android Buttons, Text View and simple functions. The UI is not so beautiful but is a great way to learn the basic functionalities.

Create Custom View in android MATRIX EFFECT CANVAS tutorial

Create Custom View in android MATRIX EFFECT CANVAS tutorial
Hi all as I stared my development with android I always wanted to create a Custom view or rather I want a canvas where I can draw freely. To learn about canvas I decided to create matrix rain effect which I can add to my android layout. Here is the complete tutorial which I have post. Hopping it will be use full to someone.

You can find the link to android project at the bottom of the post

Android Live Wallpaper Tutorial


Hi, at last I was able to create my own live wallpaper " MATRIX RAIN ". 

Download : click here

The matrix rain effect which I am using is the same which I created in canvas.
ref :- http://www.androidlearner.com/2016/09/create-custom-view-in-android-matrix.html
I this post I will describe how I put together the live wallpaper.