Моя проблема: У меня есть действие A, которое запускает службу S. A запускает другое приложение B, которое установлено в системе. Тогда S начинает активность B, в этот самый момент начинается B, вместе с A. Технически, A не должен начинаться, но это произошло. Я так смущен этим. Я действительно надеюсь, что кто-то поможет мне в этом. Я потратил на это много часов. Вот код:Начало действия от службы
public class ActivityA extends Activity{
Intent intent;
@Override
public void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.test_b);
intent = new Intent(this, TestService.class);
//start an app in the system
AppManager.getAppManager(this).launch(10);
startService(intent);
}
@Override
public void onDestroy(){
super.onDestroy();
stopService(intent);
}
}
public class TestService extends Service{
@Override
public void onCreate(){
super.onCreate();
IntentFilter onfilter = new IntentFilter(Intent.ACTION_SCREEN_ON);
registerReceiver(screenon, onfilter);
}
@Override
public void onDestroy(){
super.onDestroy();
unregisterReceiver(screenon);
}
BroadcastReceiver screenon = new BroadcastReceiver() {
public static final String TAG = "screenon";
public static final String Screen = "android.intent.action.SCREEN_ON";
@Override
public void onReceive(Context context, Intent intent) {
if (!intent.getAction().equals(Screen))
return;
//start TestLockActivity when screen on
Intent it = new Intent(TestService.this, ActivityB.class);
it.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(it);
return;
}
};
@Override
public IBinder onBind(Intent intent) {
// TODO Auto-generated method stub
return null;
}
}
public class ActivityB extends Activity{
@Override
public void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.test_lock);
}
}
запуска() метод в AppManager:
public void launch(String activityName)
{
ResolveInfo info = getResolve(activityName);
Intent intent = new Intent();
intent.setComponent(new ComponentName(info.activityInfo.applicationInfo.packageName,
activityName));
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(intent);
}
public void launch(int idx)
{
String activityName = getActivityName(idx);
launch(activityName);
}
Awesome !!! Большое спасибо. – shinado