Starting an Intent to Launch an app to Background in Android
Posted
by Tista
on Stack Overflow
See other posts from Stack Overflow
or by Tista
Published on 2010-05-16T00:58:13Z
Indexed on
2010/05/16
10:30 UTC
Read the original article
Hit count: 282
Hi all,
I'm using Wikitude API 1.1 as an AR viewer in my application. The problem with Wikitude, if I haven't launched the actual Wikitude application since the phone's bootup, I will get a NullPointerException everytime I start my own application.
So I figure if I can start my app first and them check if Wikitude is installed and or running. If it's not installed, go to market n download. If it's not running, then we should run it straight to background so that my app doesn't loose its focus.
// Workaround for Wikitude
this.WIKITUDE_PACKAGE_NAME = "com.wikitude";
PackageManager pacMan = Poligamy.this.getPackageManager();
try {
PackageInfo pacInfo = pacMan.getPackageInfo(this.WIKITUDE_PACKAGE_NAME, pacMan.GET_SERVICES);
Log.i("CheckWKTD", "Wikitude is Installed");
ActivityManager aMan = (ActivityManager) this.getSystemService(ACTIVITY_SERVICE);
List<RunningAppProcessInfo> runningApps = aMan.getRunningAppProcesses();
int numberOfApps = runningApps.size();
for(int i=0; i<numberOfApps; i++) {
if(runningApps.get(i).processName.equals(this.WIKITUDE_PACKAGE_NAME)) {
this.WIKITUDE_RUNNING = 1;
Log.i("CheckWKTD", "Wikitude is Running");
}
}
if(this.WIKITUDE_RUNNING == 0) {
Log.i("CheckWKTD", "Wikitude is NOT Running");
/*final Intent wIntent = new Intent(Intent.ACTION_MAIN, null);
wIntent.addCategory(Intent.CATEGORY_LAUNCHER);
final ComponentName cn = new ComponentName("com.wikitude",
"com.mobilizy.wikitudepremium.initial.Splash");
wIntent.setComponent(cn);
wIntent.setFlags(Intent.FLAG_ACTIVITY_NO_USER_ACTION);
startActivityIfNeeded(wIntent, 0);*/
}
} catch (NameNotFoundException e) {
// TODO Auto-generated catch block
Log.i("CheckWKTD", "Wikitude is NOT Installed");
e.printStackTrace();
//finish();
}
The part I block commented is the intent to start Wikitude. But I always failed in restricting Wikitude to background. Any help? Thanks before.
Best, Tista
© Stack Overflow or respective owner