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

  1. This website contains all the android web view.

    ReplyDelete
  2. Most of the students use education apps on android because it's easy to download as compared to IOS phones, students use this app to make them more aware of education points and they take a lot of help from this app. In fact android learner has built an app which is called best essay writing services i have used this app and it's very good.

    ReplyDelete
  3. Great tutorial useful for them who are not aware of these feature in android, they should check it out.

    ReplyDelete
  4. It's just great great post to read for android programmer. They can learn alot
    of things on this blog

    ReplyDelete

Post a Comment