Android Interview Questions and Answers What is android?



Download 0.77 Mb.
View original pdf
Page34/62
Date17.12.2020
Size0.77 Mb.
#54986
1   ...   30   31   32   33   34   35   36   37   ...   62
Android Interview Questions
1. The Intent Class
The Intent class has acquired two rather specialized factory methods. The method public static Intent makeMainActivity(ComponentName mainActivity) will return an Intent which can be used to launch an Application with the named main Activity. For example,
Intent i = Intent.makeMainActivity( new ComponentName(
"xper.honeycomb",
"xper.honycomb.XperActivity"));
System.out.println("action == " + i.getAction());
System.out.println("categories == " + i.getCategories());
System.out.println("component == " + i.getComponent());
System.out.println("flags == x" + Integer.toHexString(i.getFlags())); prints action == android.intent.action.MAIN categories == [android.intent.category.LAUNCHER] component == ComponentInfo{xper.honeycomb/xper.honycomb.XperActivity} flags == x The method public static Intent makeRestartActivityTask(ComponentName mainActivity) will return an Intent to relaunch an Application with the named main Activity. For example,
Intent j = Intent.makeRestartActivityTask( new ComponentName(
"xper.honeycomb",
"xper.honycomb.XperActivity"));
System.out.println("action == " + j.getAction());
System.out.println("categories == " + j.getCategories());


System.out.println("component == " + j.getComponent());
System.out.println("flags == x" + Integer.toHexString(j.getFlags())); prints action == android.intent.action.MAIN categories == [android.intent.category.LAUNCHER] component == ComponentInfo{xper.honeycomb/xper.honycomb.XperActivity} flags == x As can be seen the difference between the two methods is that the second one sets two flags,
Intent.FLAG_ACTIVITY_NEW_TASK(0x10000000) and
Intent.FLAG_ACTIVITY_CLEAR_TASK(0x00008000)) Quite why it is necessary to add two brand new methods for this purpose is not that obvious.

Download 0.77 Mb.

Share with your friends:
1   ...   30   31   32   33   34   35   36   37   ...   62




The database is protected by copyright ©ininet.org 2024
send message

    Main page