我发现使用留在后台的应用程序很难开始新的活动。这是我的代码:
public class App1 extends Activity{
public void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
registerReceiver(batteryInfoReceiver, new IntentFilter(Intent.ACTION_BATTERY_CHANGED));
}
private BroadcastReceiver batteryInfoReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context c, Intent i) {
Toast.makeText(getApplicationContext(), "TEST", Toast.LENGTH_LONG).show();
Intent intent = new Intent("App2.intent.action.Launch");
intent.putExtra("startedByApp", true);
startActivity(intent);
}
}
@Override
public void onBackPressed() {
moveTaskToBack(true);
}
}
public class App2 extends Activity{
public void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Toast.makeText(getApplicationContext(), "TEST 2", Toast.LENGTH_LONG).show();
}
}
当 App1 在前台时,它工作正常。当 App1 在后台 (moveToBack) 显示“TEST”时,它不会启动 App2(我的屏幕上没有“TEST 2”。
伙计们,你能帮帮我吗?