• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Apps Problem launching new Activity

D

Deleted User

Guest
I have created a new Activity in my project
Code:
public class ActivityInbox extends ListActivity implements OnClickListener, StateModelListener {

I have added to to the AndroidManifest.xml:
Code:
        <activity android:name=".ActivityInbox"></activity>

I have added code to a button on my original screen to activate it
Code:
    		Intent intentActivityInbox = new Intent(ActivityLogin.this, ActivityInbox.class);
    		startActivity(intentActivityInbox);

When the button is clicked the app explodes. I think it's down inside the following line of ActivityInbox
Code:
        setContentView(R.layout.layout_inbox);


Any ideas?
 
Here is my Activity code. Ignore the StateManager stuff. It's not hooked up
Code:
package com.mydomain.app.activity;

import java.util.ArrayList;

import android.app.ListActivity;
import android.content.Context;
import android.os.Bundle;
import android.os.Handler;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.View.OnClickListener;
import android.widget.ArrayAdapter;
import android.widget.TextView;

import com.mydomain.app.utils.*;

public class ActivityInbox extends ListActivity implements OnClickListener, StateModelListener {

	private ArrayList<MessageSummary> m_aryMessages = null;
	private InboxAdapter m_Adapter;	
	private final Runnable m_runUpdateDisplay = new Runnable() {
		public void run() {
			updateDisplay();
		}
	};
	private Runnable viewOrders;
	
	private static final String INBOX_STATE_MODEL = "InboxStateModel";
	
	// handler for thread posts
	private final Handler m_hdlHandler = new Handler();
	
	// model to manage thread state
	private StateModel m_smInbox;
	
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.layout_inbox);
        
        // if the first time in, create state model for activity
        if (m_smInbox == null) {
        	m_smInbox = new StateModel();
        }
        
        // TODO set pointers to ui controls

        
        // TODO put cache logic here
        if(savedInstanceState == null) {
        	viewOrders = new Runnable() {
        		public void run() {
        			launchInboxThread();
        		}
        	};
        	// TODO update this to use State Model
        	Thread thread = new Thread(null, viewOrders, "MagentoBackground");
        	thread.start();
        }
    }
    
    @Override
    protected void onPause() {
    	super.onPause();
    	// detach from the model
    	m_smInbox.setLoginModelListener(null);
    }
    
    @Override
    protected void onResume() {
    	super.onResume();
    	// attach to the model
    	m_smInbox.setLoginModelListener(this);
    	
    	// synchronize the display, in case the thread completed
    	// while this activity was not visible.  For example, if
    	// a phone call occurred while the thread was running.
    	updateDisplay();
    }
    
    public void stateModelChanged(StateModel lm) {
    	// this may be called from a background thread, so post to the handler
    	m_hdlHandler.post(m_runUpdateDisplay);
    }
	
	public void onClick(View v) {

	}
	
    @Override
    protected void onSaveInstanceState(Bundle outState) {
    	super.onSaveInstanceState(outState);
    	
    	// save screen state
    	outState.putSerializable(INBOX_STATE_MODEL, m_smInbox);
    }
    
    @Override
    public void onRestoreInstanceState(Bundle savedInstanceState)
    {
        super.onRestoreInstanceState(savedInstanceState);
        
        // restore screen state
        if (savedInstanceState != null) {
        	if (savedInstanceState.containsKey(INBOX_STATE_MODEL)) {
        		m_smInbox = (StateModel)savedInstanceState.getSerializable(INBOX_STATE_MODEL);
        	}
        }
    }

	private final Runnable returnRes = new Runnable() {
		public void run() {
			if(m_aryMessages != null && m_aryMessages.size() > 0) {
				m_Adapter.notifyDataSetChanged();
                for(int i=0;i<m_aryMessages.size();i++)
                    m_Adapter.add(m_aryMessages.get(i));
                m_Adapter.notifyDataSetChanged();
			}
		}
	};
    
      
    private void launchInboxThread() {
    	// TODO launch inbox thread
        m_aryMessages = new ArrayList<MessageSummary>();
        MessageSummary msgSum = new MessageSummary();
        msgSum.setMessage("SF services");
        msgSum.setSummary("Pending");
        MessageSummary msgSum2 = new MessageSummary();
        msgSum2.setMessage("SF advertisement");
        msgSum2.setSummary("Completed");
        m_aryMessages.add(msgSum);
        m_aryMessages.add(msgSum2);
        
        runOnUiThread(returnRes);
    }
    
    private void updateDisplay() {
    	// TODO update display
    }
}










final class InboxAdapter extends ArrayAdapter<MessageSummary> {

    private ArrayList<MessageSummary> items;

    public InboxAdapter(Context context, int textViewResourceId, ArrayList<MessageSummary> items) {
            super(context, textViewResourceId, items);
            this.items = items;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
    		super.getView(position, convertView, parent);
    	
            View v = convertView;
            if (v == null) {
                LayoutInflater vi = (LayoutInflater)getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
                v = vi.inflate(R.layout.layout_inbox_item, null);
            }
            MessageSummary msgSum = items.get(position);
            if (msgSum != null) {
                    TextView tt = (TextView) v.findViewById(R.id.toptext);
                    TextView bt = (TextView) v.findViewById(R.id.bottomtext);
                    if (tt != null) {
                          tt.setText("Name: "+msgSum.getMessage());
                    }
                    if(bt != null) {
                          bt.setText("Status: "+ msgSum.getSummary());
                    }
            }
            return v;
    }
}



Here is my layout xml
Code:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    >
    <ListView
    	android:id="@+id/android:list"
    	android:layout_width="fill_parent"
    	android:layout_height="fill_parent"
    />
	<TextView
    	android:id="@+id/android:empty"
    	android:layout_width="fill_parent"
    	android:layout_height="fill_parent"
    	android:text="@string/inbox_no_items"
    />
</LinearLayout>





I have noticed that android:list and android:empty do not exist in R.java under the id tag. Is this ok? I'm following the tutorial here.
 
Upvote 0

BEST TECH IN 2023

We've been tracking upcoming products and ranking the best tech since 2007. Thanks for trusting our opinion: we get rewarded through affiliate links that earn us a commission and we invite you to learn more about us.

Smartphones