Reputation: 81
I find it difficult to start new activity using application staying in the background. Here is my code:
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();
}
}
When App1 is in the foreground it works fine. When App1 is in the background (moveToBack) it shows "TEST", but it doesn't start App2 (there is no "TEST 2" on my screen.
Guys, can you help me?
Upvotes: 2
Views: 108