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
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
I have a button in my app named "Go Home" to redirect the user to the home screen. It is working fine without the very first launch. The process of first launch is noted below:
After uploading the APK into SVN I am downloading using the web browser. Then go back to the download folder and installing the app. When install finishes I click on Open. Then In my app I click on the "Go Home" button. The application redirect me to the web browser instead of the home screen. I am tired to search a solution for that.
I am using the following code:
finish();
Intent intent = new Intent(Intent.ACTION_MAIN);
intent.addCategory(Intent.CATEGORY_HOME);
startActivity(intent);
Thanks in advance, Siddiqui Noor
Your app is opening in the task of the browser. Try this:
finish();
Intent intent = new Intent(context, HomeActivity.class);
intent.setAction(Intent.ACTION_MAIN)
.addCategory(Intent.CATEGORY_HOME)
.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);
try adding FLAG_ACTIVITY_NEW_TASK:
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
and also try putting finish() after startActivity
I'm pretty sure that it's not really redirecting you anywhere, it's just closing the Activity. You call finish() after which the intent to start the activity never happens. The app is closed because you've finished the Activity and you end up looking at the screen that was showing before you opened the app. In this case, that is the browser.
Try removing the line to finish();
Intent intent = new Intent(Intent.ACTION_MAIN);
intent.addCategory(Intent.CATEGORY_HOME);
startActivity(intent);
kill your current activity after redirect the next activity
finish();
I use the following code snippet to launch an app on device:
Context mContext = getContext();
String packageName = getPackageName(); //the app to launch
Intent mIntent = getPackageManager().getLaunchIntentForPackage(packageName);
if(mIntent!=null){
mContext.startActivity(mIntent);
}
It works, the app get launched, however, I don't figure out a way to close the launched app by using the packageName.
How to close the launched app if I only know the package name?
You cannot close another app. Only the system can do that.
But if you are also the author of that other app, you could create a receiver in that app's activities that accepts an intent that tells it to finish() the activities.
You cannot close other application from your app.your problem has a workaround,after starting app based on package name you may send home intent which will give same experience to user.
Intent mIntent = getPackageManager().getLaunchIntentForPackage(packageName);
if(mIntent!=null){
mContext.startActivity(mIntent);
}
//sleep for 250ms or whatever time using handler
Intent startMain = new Intent(Intent.ACTION_MAIN);
startMain.addCategory(Intent.CATEGORY_HOME);
startMain.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(startMain);
I have succeeded in launching the default home launcher through the following code while working with the emulator:
Intent de_intent=new Intent();
de_intent.setClassName("com.android.launcher","com.android.launcher2.Launcher");
startActivity(de_intent);
But when I am executing this code in the real device, it is showing following exception:
Unable to find explicit activity class {com.android.launcher/com.android.launcher2.Launcher} have you declared this in AndroidManifest.xml
Can anybody help me to solve this issue?
Do you have a Samsung device? They replaced the default Android launcher with their TouchWiz Home launcher. The following code worked for me using the setClassName() method:
Intent intent = new Intent(Intent.ACTION_MAIN);
intent.setClassName("com.sec.android.app.launcher", "com.android.launcher2.Launcher");
startActivity(intent);
try following:
Intent startMain = new Intent(Intent.ACTION_MAIN);
startMain.addCategory(Intent.CATEGORY_HOME);
startMain.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(startMain);
If you want to return to HOME, you can use:
Intent intent = new Intent(Intent.ACTION_MAIN);
intent.addCategory(Intent.CATEGORY_HOME);
startActivity(intent);
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