Mocktheduck Mocktheduck - 21 days ago 5
Android Question

Android won't load new activity

I'm trying to load the data from an XML in a new activity on a button click. The problem is, nothing really happens when I click the button. It doesn't crash, the application just becomes unresponsive and that's all. It won't go the the next activity. Any ideas?

main activity:

public void onSignupSuccess() {
_signupButton.setEnabled(true);
setResult(RESULT_OK, null);
String toSend = "mailto:" + _nameText.getText().toString();
String email = _emailText.getText().toString();
String[] toArr = {email};
try {
if(sendEmail()) {
Toast.makeText(this, "Email was sent successfully.", Toast.LENGTH_LONG).show();
Intent myIntent = new Intent(MainActivity.this, ListItemsActivity.class);
Log.d(TAG, "Trying to move to the next pane");
startActivity(myIntent);
} else {
Toast.makeText(this, "Email was not sent.", Toast.LENGTH_LONG).show();
}
} catch(Exception e) {
Log.e("MailApp", "Could not send email", e);
}
}


list activity

public class ListItemsActivity extends Activity {
ListView listView;
private static final String TAG = "ListActivity";

@Override
public void onCreate(Bundle savedInstanceState) {
Log.d(TAG, "Trying to create the list activitye");
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.activity_main);


//* *EDIT* *
this.listView = (ListView) findViewById(R.id.listView1);
}
}


my list activity

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/activity_list_items"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="com.example.melisaam.logintest.ListItemsActivity">

<ListView
android:id="@+id/listView1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:entries="@array/sections" >
</ListView>

</RelativeLayout>


array.xml

<?xml version="1.0" encoding="utf-8"?>
<resources>
<string-array name="sections">
<item >Pro Constructive</item>
<item >Con Constructive</item>
<item >1st Speaker Cross</item>
<item >Pro Rebbutal</item>
<item >Con Rebuttal</item>
<item >2nd Speaker Cross</item>
<item >Pro Summary</item>
<item >Con Summary</item>
<item >Grand Cross</item>
<item >Pro Final Focus</item>
<item >Con Final Focus</item>
</string-array>
</resources>


And my manifest

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.melisaam.logintest">

<uses-permission android:name="android.permission.INTERNET" />

<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme">
<activity
android:name=".MainActivity"
android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".ListItemsActivity" />
<activity android:name=".SingleListItem"></activity>
</application>

</manifest>


Here are my logs. I can't make anything out of this.

D/ListActivity: Trying to create the list activitye
D/TextView: setTypeface with style : 0
D/Activity: performCreate Call Injection manager
I/InjectionManager: dispatchOnViewCreated > Target : com.example.melisaam.logintest.ListItemsActivity isFragment :false
D/SecWifiDisplayUtil: Metadata value : SecSettings2
D/ViewRootImpl: #1 mView = com.android.internal.policy.PhoneWindow$DecorView{64e0b62 I.E...... R.....ID 0,0-0,0}
V/RenderScript: 0x7f613b7000 Launching thread(s), CPUs 8
D/mali_winsys: new_window_surface returns 0x3000, [1440x2560]-format:1
D/ViewRootImpl: MSG_RESIZED_REPORT: ci=Rect(0, 0 - 0, 0) vi=Rect(0, 0 - 0, 0) or=1
D/ViewRootImpl: MSG_RESIZED_REPORT: ci=Rect(0, 96 - 0, 0) vi=Rect(0, 96 - 0, 0) or=1
E/SpannableStringBuilder: SPAN_EXCLUSIVE_EXCLUSIVE spans cannot have a zero length
E/SpannableStringBuilder: SPAN_EXCLUSIVE_EXCLUSIVE spans cannot have a zero length
I/Timeline: Timeline: Activity_idle id: android.os.BinderProxy@dafc17b time:249820080
V/ActivityThread: updateVisibility : ActivityRecord{3c16e43 token=android.os.BinderProxy@2687817 {com.example.melisaam.logintest/com.example.melisaam.logintest.MainActivity}} show : false
D/ViewRootImpl: #3 mView = null


I dont understand why it's not working. Do I have to do something additional?

EDIT:

public boolean sendEmail() {
try {
Intent sendIntent = new Intent(Intent.ACTION_SEND);
sendIntent.setType("plain/text");
sendIntent.setData(Uri.parse("moismelisa@yahoo.com"));


sendIntent.setClassName("com.google.android.gm","com.google.android.gm.ComposeActivityGmail");
sendIntent.putExtra(Intent.EXTRA_SUBJECT, "Registration Trucks for Sale");
String message = "I'd like to register on your site with the following information" + "\n" +
"Username: " + _nameText.getText().toString() + "\n" +
"Email: " + _emailText.getText().toString() + "\n" +
"Password: " + _passwordText.getText().toString() + "\n" +
"Thank you!";
sendIntent.putExtra(Intent.EXTRA_TEXT, message);
startActivity(sendIntent);
} catch (Exception e) {
return false;
}
return true;
}


On debug, the this.listView is null. So this line does nothing:
this.listView = (ListView) findViewById(R.id.listView1);

Answer

You have used R.layout.activity_main as your layout in the ListItemsActivity. If that is the layout to the main activity, then that is the problem

setContentView(R.layout.activity_main);