Now my problem : I wrote a function to put an application in the foreground, it works fine for every applications, except for one: the launcher (com.android.launcher).
The function :
public void switchTo(String activityName)
{
Intent intent=new Intent(Intent.ACTION_MAIN);
try
{
//Specials cases (Contacts and launcher app)
if(activityName.equalsIgnoreCase("com.android.contacts"))
{
intent.setComponent(new ComponentName("com.android.contacts","com.android.contacts.DialtactsContactsEntryActivity" ));
}
else
{
intent=this.packageManager.getLaunchIntentForPackage(activityName);
}
if(null != intent)
{
intent.addFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
this.activity.startActivity(intent);
this.activity.finish();
}
}
catch (ActivityNotFoundException e)
{
e.printStackTrace();
}
}
When "activityName" is equal to "com.android.launcher", nothing happens, not even an exception, but the function is called (I verified with a "Log" function).
So do you have 开发者_运维问答any idea of where the mistake is?
I finally find an answer to my question, i just have to add a case if the process name is "com.android.launcher" and put in this case :
intent.addCategory(Intent.CATEGORY_HOME);
Thanks for reading my problem and i hope this can help some people here !
精彩评论