I have minimized my app using this..
Intent startMain = new Intent(Intent.ACTION_MAIN);
startMain.addCategory(Intent.CATEGORY_HOME);
startMain.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(startMain);
The app is waiting for some event while it is in minimized state.How can i return to the app activity when some broadcast event occurs?
i can access the minimized activity from the the broadcast receiver class(using an object passed to it earlier) but it is running in the background of home screen.
and does android kill minimized apps eventually?
Intent homeIntent = new Intent(this, HomeActivity.class);
homeIntent.addFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
startActivity(homeIntent);
this will start the HomeActivity, if the activity still in memory, it will just bring it to front.
You can start the activity again using the Intent.
Example :
Intent intent = new Intent(Intent.ACTION_MAIN);
intent.setComponent(new ComponentName("com.package.address","com.package.address.MainActivity"));
startActivity(intent);
If you want to maximize the application you need user interface in that case you can add your application in notification bar, once user click on notification bar you can open in your word can maximize the same. Adding your application in to notification bar you can get many tutorials :
Notification
Related
I need to send an app to background, return home and call it from background again in Android, with Appium.
I've alredy tried
driver.runAppInBackground(seconds);
and
driver.launchApp();
but they re-launch the application, don't call it.
How should I handle this?
Thank you in advance.
Try this way, to start home screen:
Intent startMain = new Intent(Intent.ACTION_MAIN);
startMain.addCategory(Intent.CATEGORY_HOME);
startMain.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(startMain);
And from background service after some time or event, you can start you main activity again the same way:
Intent intent = new Intent();
intent.setComponent(new ComponentName("com.example", "com.example.MyExampleActivity"));
startActivity(intent);
You can start any application activity using intents.
I did something like this just now, but the difference is I called another app(so basically putting the app in background). The way i runned the app from background is long press home button with adb shell input keyevent --longpress 3, then used .click() on the app i want to run from background. You can use UIAutomatorViewer to find the element :). Hope this helps
When user press "Home Button" my app go to Background, but is still running. I need bring my app to front again. For example i've this code:
Context ctx=getApplicationContext();
Intent i =ctx.getPackageManager().getLaunchIntentForPackage("com.example.test");
ctx.startActivity(i);
but this code is to open app in different activity, there are a method or something to do this "correctly"?
You can simulate the "launching" of the app the same way that Android launches the app when the user selects it from the list of available apps. If the user starts an application that is already running, Android just brings the existing task to the foreground (which is what you want). Do it like this:
Intent intent = new Intent(context, SplashScreen.class);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); // You need this if starting
// the activity from a service
intent.setAction(Intent.ACTION_MAIN);
intent.addCategory(Intent.CATEGORY_LAUNCHER);
startActivity(intent);
(Source: https://stackoverflow.com/a/12075313/3529926)
You can set this flag to your intent
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
and set the launch mode of your activity to single task in manifest (add this is your activity tags):
android:launchMode="singleTask"
I am developing two apps that will be installed on the same device. My customer wants a shortcut button on each to jump to the other app in its current state. This action would duplicate the behavior of pressing HOME then pressing the other app's launcher icon. If the app has not been started, it would start it. If the app has already been started, then the current activity is resumed. Each app has many activities, so the current activity at the top of each app's task stack would be unknown at run-time. I have searched all over and have not found this problem answer sufficiently. I have tried variations on this code without success:
Intent intent = getPackageManager().getLaunchIntentForPackage("com.example");
intent.setAction(Intent.ACTION_MAIN);
intent.addCategory(Intent.CATEGORY_LAUNCHER);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);
I am at a loss, any help is appreciated.
I figured out my problem. Here is what works:
Intent intent = new Intent();
intent.setComponent(new ComponentName("com.example", "com.example.MyActivity"));
intent.setAction(Intent.ACTION_MAIN);
intent.addCategory(Intent.CATEGORY_LAUNCHER);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);
I Want to design an App. Which will start on mobile restart.
I am able to start my activity by using "android.intent.action.BOOT_COMPLETED" intent
but "SAMSUNG NOTE" has facility to restart mobile not needed to switch off and then on
here i am facing problem my app is not starting on "restart"
Problem Solved for now by removing code which is commented.
Intent startMainActivity = new Intent(context,MyActivity.class);
startMainActivity.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(startMainActivity);
/* Intent startMain = new Intent(Intent.ACTION_MAIN);
startMain.addCategory(Intent.CATEGORY_HOME);
startMain.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(startMain);*/
I was using commented code to launch home screen after my app is launched
I am working in a service, on device boot my service starts along with application.
Now if service finds some restricted apps launched, it backgrounds my application, shows home, kill app, and start again activity to foreground. But it is creating multiple instances when starting activity on boot.
I want to start previously launched activity every time if it exists, I am using the following code:
//activity to background
Intent startMain = new Intent(Intent.ACTION_MAIN);
startMain.addCategory(Intent.CATEGORY_HOME);
startMain.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(startMain);
//killing restricted app
Appmgr.killBackgroundProcesses(RunningP.processName);
//again start activity
Intent intent = new Intent();
intent.setAction(Intent.ACTION_MAIN);
intent.addCategory(Intent.CATEGORY_LAUNCHER);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
ComponentName cn = new ComponentName(this, TaxiPlexer.class);
intent.setComponent(cn);
startActivity(intent);
I have used FLAG_ACTIVITY_LAUNCHED_FROM_HISTORY and others but they are giving me force close error. Above code only creates multiple instances ON BOOT
add this to manifest:
<activity android:name="yourActivity" launchMode = "singleTask" ></activity>