Going to Home Screen Programmatically

Going to home screen programmatically

You can do this through an Intent.

Intent startMain = new Intent(Intent.ACTION_MAIN);
startMain.addCategory(Intent.CATEGORY_HOME);
startMain.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(startMain);

This Intent will start the launcher application that the user has defined. Be careful with this because this will look like your application crashed if the user does not expect this.

If you want this to build an exit button from your app please read this article on exit Buttons in Android

How to Go to home screen programmatically

You can use the following method

this.moveTaskToBack(true); //if you are inside activity

Elsewhere

activity.moveTaskToBack(true); //activity is the reference of your Activity.

Read more about this method here moveToBack)

Yet another android show home screen programmatically

Ok, so I haven't solved the actual two problems in the post, which is related to programming. However, I have solved what I wanted to do (ref backstory).

So basically what I did was to install tasker and tasker app factory. In tasker I made a task to show the home screen. Also here it needs to be executed twice to go to the "home-home screen". Add a delay of 100 ms between the two. It looks very smooth. No windows are popping up and it's a nice smooth transition from what ever app you reside in, to the home screen, then it glides to the "home-home screen". Export this task and configure the smart button to run this when the smart button is clicked.

How to go to the default home screen of Android programatically?

Try this:

Intent homeIntent= new Intent(Intent.ACTION_MAIN);
homeIntent.addCategory(Intent.CATEGORY_HOME);
homeIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(homeIntent);

Set App Widget to Home Screen programmatically


i want that after click on button from my activity widget will be set to home screen without going here

That is not possible.

creating android app shortcut on the home screen

Do like This:

Step 1:

Update your manifest.xml :

  <uses-permission
android:name="com.android.launcher.permission.INSTALL_SHORTCUT" />

Step 2:

in your MainActivity.java create addShortcut() method and in it`s block put this code :

private void addShourcut(){
Intent shortCutIntent = new Intent(getApplicationContext() ,MainActivity.class);

shortCutIntent.setAction(Intent.ACTION_MAIN);

Intent addIntent = new Intent();

addIntent.putExtra(Intent.EXTRA_SHORTCUT_INTENT , shortCutIntent);
addIntent.putExtra(Intent.EXTRA_SHORTCUT_NAME , "Convertor");
addIntent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE ,
Intent.ShortcutIconResource.fromContext(getApplicationContext() , R.mipmap.ic_launcher));
addIntent.setAction("com.android.launcher.action.INSTALL_SHORTCUT");
addIntent.putExtra("duplicate" , false);
getApplicationContext().sendBroadcast(addIntent);

}

Step3:

set onClickListener for your view that be create shortcut :

img_pin = (ImageView) findViewById(R.id.img_pin);
img_pin.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {

addShourcut();
Toast.makeText(MainActivity.this, "shortcut created !", Toast.LENGTH_SHORT).show();

}
});

This is worked for me ...
happy codinngggg...:)

iOS: Exit from the app to Home Screen programmatically with gracefully exit with animation?


Code:

   @IBAction func minimizeOrKillApp(){            
UIControl().sendAction(#selector(URLSessionTask.suspend), to: UIApplication.shared, for: nil)
//Comment if you want to minimise app
Timer.scheduledTimer(withTimeInterval: 0.2, repeats: false) { (timer) in
exit(0)
}
}

Output

Download sample code

It is not recommended and your app will be rejected. We all are the developers and We know to how to approve it from reviewer team

Apple developer question



Related Topics



Leave a reply



Submit