how to programatically pause an application?

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


Sponsored Links
 Hi,

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

thanks

    guich

--



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
CommonsWare
mmur...@commonsware.com
 http://commonsware.com 

--


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?

thx

  guich

--



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);
        mHomeIntent.addCategory(Intent.CATEGORY_HOME);
        mHomeIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK
                | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);

-joe









--



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:

http://developer.android.com/sdk/index.html


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

http://developer.android.com/resources/tutorials/hello-world.html

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 /
Users/mydirectory/Documents/workspace/HelloAndroid/gen/com/example/
helloandroid/R.java: No such file or directory

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

setContentView(R.layout.main);

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
tutorial.

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
speeches
     * 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
supplied
        // 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
views
            // we want to bind data to.
            holder = new ViewHolder();
            holder.Di = DetailItems.get(position);
            holder.Caption = (TextView)
convertView.findViewById(R.id.txtCaption);
            holder.SetEditor((EditText)
convertView.findViewById(R.id.txtEditor));

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

        holder.Editor.setMinLines(holder.Di.MaxLines);
        holder.Editor.setMaxLines(holder.Di.MaxLines);

        holder.Editor.setInputType(holder.Di.getDefaultInputType());

        if (holder.Di.Password == true){
         holder.Editor.setTransformationMethod(new
PasswordTransformationMethod());
        }else{
         holder.Editor.setTransformationMethod(null);
        }

        holder.Editor.setHint(holder.Di.Hint);
        holder.Editor.setText(holder.Di.Value);
        holder.Caption.setText(holder.Di.Caption);

        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.setOnFocusChangeListener(null);
         Editor.addTextChangedListener(null);
         }
         Editor = theEditor;
         Editor.setOnFocusChangeListener(this);
         Editor.addTextChangedListener(this);
        }

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