I am learning to create Android applications and I need some help. It seems I can’t understand which bits of the template code I need to change and which bits are static.
In the LAYOUT folder, I have ACTIVITY_MAIN.XML that reads
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="horizontal"> <Button android:id="@+id/button1" android:layout_width="match_parent" android:layout_height="wrap_content" android:text="@string/main_buttons_photos" /> </LinearLayout>
Then I have a second activity ACTIVITY_SEND_PHOTOS.XML , which
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" > <TextView android:id="@+id/textView2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerHorizontal="true" android:layout_centerVertical="true" android:text="@string/hello_world" tools:context=".SendPhotos" /> <TextView android:id="@+id/textView1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentLeft="true" android:layout_alignParentTop="true" android:text="@string/title_activity_send_photos" android:textAppearance="?android:attr/textAppearanceLarge" /> </RelativeLayout>
Then I have MainActivity.java (is this .class?) That reads the package com.example.assent.bc;
import android.os.Bundle; import android.app.Activity; import android.view.Menu; import android.view.View; public class MainActivity extends Activity { @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); } @Override public boolean onCreateOptionsMenu(Menu menu) { getMenuInflater().inflate(R.menu.activity_main, menu); return true; } public void sendMessage(View view) {
and then the file SendPhotos.java , which:
package com.example.assent.bc; import android.os.Bundle; import android.app.Activity; import android.view.Menu; import android.view.MenuItem; import android.support.v4.app.NavUtils; public class SendPhotos extends Activity { @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_send_photos); getActionBar().setDisplayHomeAsUpEnabled(true); } @Override public boolean onCreateOptionsMenu(Menu menu) { getMenuInflater().inflate(R.menu.activity_send_photos, menu); return true; } @Override public boolean onOptionsItemSelected(MenuItem item) { switch (item.getItemId()) { case android.R.id.home: NavUtils.navigateUpFromSameTask(this); return true; } return super.onOptionsItemSelected(item); } }
I would like the button in my main action to communicate with my sendphotos activity, simply opening this activity, nothing unusual, not sending any data or anything else.
I know that somewhere I need mine
Intent i = new Intent(FromActivity.this, ToActivity.class); startActivity(i);
but I have no idea what to replace ToActivity.class or what else I need.
android android-intent android-activity
Henry Aspden Nov 02 '12 at 11:12 2012-11-02 11:12
source share