how to programatically pause an application?

by guich » Tue, 15 Jun 2010 22:03:47 GMT

Sponsored Links

How can i simulate pressing the HOME key to put my application in
pause mode? Currently i call finish() but it destroys the application.




how to programatically pause an application?

by Mark Murphy » Tue, 15 Jun 2010 22:06:55 GMT


Call startActivity() on an Intent with ACTION_MAIN with category
CATEGORY_HOME -- that will launch the home screen.

Mark Murphy


Sponsored Links

how to programatically pause an application?

by guich » Tue, 15 Jun 2010 22:42:56 GMT

 Thanks, but something went wrong.
I can see the onPause and onResume being called for my app, but the
screen is blank after the resume. This does not happen when i press
the home key.

Maybe there's a way to simulate the home key?




how to programatically pause an application?

by Joe Onorato » Wed, 16 Jun 2010 05:50:30 GMT

 This is the intent that's launched when you press the home key:

        mHomeIntent =  new Intent(Intent.ACTION_MAIN, null);
                | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);



Other Threads

1. tutorial not working

I'm on Mac OS X Leopard and installed the ADT plugin into Eclipse
Galileo.  I followed all these steps to get started:

My SDK version is 2.2 API 8 revision 2 and I just used the Hello World
tutorial found here:

When I first created the Android application, I saw this error in the
Eclipse console:

[2010-11-13 18:20:43 - HelloAndroid] ERROR: Unable to open class file /
helloandroid/ No such file or directory

I commented out this line to fill in the few lines from the tutorial:


When I ran the app, it launched my emulator but all I saw was a
vertical screen on the left that said "ANDROID" and phone buttons on
the right.  I did not see the "Hello, Android" text from the

Any ideas?


2. Editing Data in BaseAdapter (forgive me if this is a repost)

I'm trying to extend BaseAdapter and Edit Data in that extension. (full
source code to class is below) I'm having several focus issues. The first
issue is that I must touch the "EditText" field several times to get focus.
On the Droid X the soft keyboard never shows. On the ADP2 once I type one
letter the auto complete bar shows for a moment then disappears, then I lose
focus for the field I was just editing.

package net.ideposit.classes;

import java.util.List;

import net.ideposit.R;
import net.ideposit.entities.DetailItem;
import android.content.Context;
import android.text.Editable;
import android.text.Tex{*filter*}cher;
import android.text.method.PasswordTransformationMethod;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.View.OnFocusChangeListener;
import android.widget.BaseAdapter;
import android.widget.EditText;
import android.widget.TextView;

public class TransactionAdapter extends BaseAdapter {
    private LayoutInflater mInflater;
    private List<DetailItem> DetailItems;

    public TransactionAdapter(Context context,List<DetailItem> DetailItems)
        // Cache the LayoutInflate to avoid asking for a new one each time.
        mInflater = LayoutInflater.from(context);
        this.DetailItems = DetailItems;

     * The number of items in the list is determined by the number of
     * in our array.
     * @see android.widget.ListAdapter#getCount()
    public int getCount() {
        return DetailItems.size();

     * Since the data comes from an array, just returning the index is
     * sufficent to get at the data. If we were using a more complex data
     * structure, we would return whatever object represents one row in the
     * list.
     * @see android.widget.ListAdapter#getItem(int)
    public Object getItem(int position) {
        return position;

     * Use the array index as a unique id.
     * @see android.widget.ListAdapter#getItemId(int)
    public long getItemId(int position) {
        return position;

     * Make a view to hold each row.
     * @see android.widget.ListAdapter#getView(int, android.view.View,
     *      android.view.ViewGroup)
    public View getView(int position, View convertView, ViewGroup parent) {
        // A ViewHolder keeps references to children views to avoid
unneccessary calls
        // to findViewById() on each row.
        ViewHolder holder;

        // When convertView is not null, we can reuse it directly, there is
no need
        // to reinflate it. We only inflate a new View when the convertView
        // by ListView is null.
        if (convertView == null) {
            convertView = mInflater.inflate(R.layout.field_layout, null);

            // Creates a ViewHolder and store references to the two children
            // we want to bind data to.
            holder = new ViewHolder();
            holder.Di = DetailItems.get(position);
            holder.Caption = (TextView)

        } else {
            // Get the ViewHolder back to get fast access to the TextView
            // and the ImageView.
            holder = (ViewHolder) convertView.getTag();
            holder.Di = DetailItems.get(position);



        if (holder.Di.Password == true){


        return convertView;

    private class ViewHolder implements OnFocusChangeListener, Tex{*filter*}cher {
        TextView Caption;
        EditText Editor;
        DetailItem Di;
        boolean HasFocus = false;
        public void SetEditor(EditText theEditor){
         if (Editor != null){
         Editor = theEditor;

public void onFocusChange(View arg0, boolean arg1) {
 HasFocus = arg1;

public void afterTextChanged(Editable arg0) {
 // not used

public void beforeTextChanged(CharSequence arg0, int arg1, int arg2,int
arg3) {
// not used

public void onTextChanged(CharSequence arg0, int arg1, int arg2,
 int arg3) {
if (HasFocus){
Di.Value = Editor.getText().toString();



3. DatePickerDialog onDateSet crashes my code

4. Spinner: crash when selected

5. Hai

6. How to promote my Android application on the Android market

7. Platform Library Example - The Details I Don't Get