xml - Using AliasActivity in android -



xml - Using AliasActivity in android -

according documentation aliasactivity stub can used choosing activity start. aliasactivity ordinar activity, parse android.app.alias tag utilize xml file start activity. in android manifest file can used like:

<activity android:name="android.app.aliasactivity" android:label="@string/app_name" > <intent-filter> <action android:name="android.intent.action.main" /> <category android:name="android.intent.category.launcher" /> </intent-filter> <meta-data android:name="android.app.alias" android:resource="@xml/alias" /> </activity>

after searching i've found alias.xml may looks like:

<?xml version="1.0" encoding="utf-8"?> <alias xmlns:android="http://schemas.android.com/apk/res/android"> <intent android:targetpackage="com.example.aliasexample" android:targetclass="com.example.aliasexample.mainactivity" android:data="http://www.google-shmoogle.com/"> </intent> </alias>

so how utilize aliasactivity. not finding solution, want find elegant one, , trying utilize aliasactivity. example, should start 1 activity in case of shared preference set , 1 if not set. possible utilize aliasactivity or can used device-specific characteristics, specify in xml? reason of using aliasactivity?

and sec question can access sharedpreference value straight in xml?

to open different activities based on sharedpreference value, can utilize regular activity class. within oncreate() check required valued , start activity there , phone call finish() in first activity. it'll appear if first activity not there.

an alias activity tag used define multiple launcher activities. you'll see multiple app icons app, depending on manifest. example here.

edit 1: couldn't find implementation of aliasactivity @ place one. adding huge source code. self explanatory.

/** * stub activity launches activity (and finishes itself) * based on info in component's manifest meta-data. * simple way implement alias-like mechanism. * * utilize activity, should include in manifest associated * component entry named "android.app.alias". reference xml * resource describing intent launches real application. */ public class aliasactivity extends activity { /** * name under should store in component * meta-data info alias. reference xml * resource describing intent launches real application. * {@hide} */ public final string alias_meta_data = "android.app.alias"; @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); xmlresourceparser parser = null; seek { activityinfo ai = getpackagemanager().getactivityinfo( getcomponentname(), packagemanager.get_meta_data); parser = ai.loadxmlmetadata(getpackagemanager(), alias_meta_data); if (parser == null) { throw new runtimeexception("alias requires meta-data field " + alias_meta_data); } intent intent = parsealias(parser); if (intent == null) { throw new runtimeexception( "no <intent> tag found in alias description"); } startactivity(intent); finish(); } grab (packagemanager.namenotfoundexception e) { throw new runtimeexception("error parsing alias", e); } grab (xmlpullparserexception e) { throw new runtimeexception("error parsing alias", e); } grab (ioexception e) { throw new runtimeexception("error parsing alias", e); } { if (parser != null) parser.close(); } } private intent parsealias(xmlpullparser parser) throws xmlpullparserexception, ioexception { attributeset attrs = xml.asattributeset(parser); intent intent = null; int type; while ((type=parser.next()) != xmlpullparser.end_document && type != xmlpullparser.start_tag) { } string nodename = parser.getname(); if (!"alias".equals(nodename)) { throw new runtimeexception( "alias meta-data must start <alias> tag; found" + nodename + " @ " + parser.getpositiondescription()); } int outerdepth = parser.getdepth(); while ((type=parser.next()) != xmlpullparser.end_document && (type != xmlpullparser.end_tag || parser.getdepth() > outerdepth)) { if (type == xmlpullparser.end_tag || type == xmlpullparser.text) { continue; } nodename = parser.getname(); if ("intent".equals(nodename)) { intent gotintent = intent.parseintent(getresources(), parser, attrs); if (intent == null) intent = gotintent; } else { xmlutils.skipcurrenttag(parser); } } homecoming intent; } }

android xml

Comments

Popular posts from this blog

php - Android app custom user registration and login with cookie using facebook sdk -

django - Access session in user model .save() -

php - .htaccess Multiple Rewrite Rules / Prioritizing -