0

Well as the title says: I'm trying to implement a button I can use to open the provided camera of the device my app is running on and then show it in my app in an ImageView. I'm doing this from a different Class and Layout and not from my Main Menu. Still after taking the picture it won't let me see it in my ImageView which is located in my AddRechnung.xml but it will drop me back into my Main Menu.

public class AddRechnung extends Activity implements View.OnClickListener{


Spinner s;
Button GoBack2,AddRechnungHin;
Intent GoBackToMain2, iCam;
ImageButton ibCam;
ImageView ivCam;
final static int cameraData = 0;
Bitmap bmp;
private String array_spinner[];
public static int Nahrung,Kleidung,Miete,Feiern;
String RechnungString = "";
EditText RechnungValue;


@SuppressWarnings({ "rawtypes", "unchecked" })
@Override
protected void onCreate(Bundle savedInstanceState) {

    // TODO Auto-generated method stub
    super.onCreate(savedInstanceState);
    setContentView(R.layout.addrechnung);
    LoadVariables();
    GoBack2.setOnClickListener(this);       
    s = (Spinner) findViewById(R.id.spinner1);
    ArrayAdapter adapter = new ArrayAdapter(this,android.R.layout.simple_spinner_item, array_spinner);
    s.setAdapter(adapter);      
    AddRechnungHin.setOnClickListener(this);
    ibCam.setOnClickListener(this);

}

private void LoadVariables() {
    // TODO Auto-generated method stub
    GoBackToMain2 = new Intent("com.lunarrepublic.STARTINGPOINT");
    GoBack2 = (Button) findViewById(R.id.button6);
    RechnungValue = (EditText) findViewById(R.id.editText2);
    array_spinner = new String[4];
    array_spinner[0] = "Nahrung";
    array_spinner[1] = "Kleidung";
    array_spinner[2] = "Miete";
    array_spinner[3] = "Feiern";
    AddRechnungHin = (Button) findViewById(R.id.button9);
    ibCam = (ImageButton) findViewById(R.id.ibCamera);
    ivCam = (ImageView) findViewById(R.id.ivCamera);
}

@Override
protected void onPause() {
    // TODO Auto-generated method stub
    super.onPause();
    finish();
}

@Override
public void onClick(View v) {
    // TODO Auto-generated method stub
    switch(v.getId()){
    case R.id.button6:
        startActivity(GoBackToMain2);
        break;
    case R.id.button9:
        RechnungString = RechnungValue.getText().toString();
        if(s.getSelectedItem().toString().equals("Nahrung")){
            Nahrung = Integer.parseInt(RechnungString);
        }else if (s.getSelectedItem().toString().equals("Kleidung")){
            Kleidung = Integer.parseInt(RechnungString);
        }else if (s.getSelectedItem().toString().equals("Miete")){
            Miete = Integer.parseInt(RechnungString);
        }else if (s.getSelectedItem().toString().equals("Feiern")){
            Feiern = Integer.parseInt(RechnungString);
        }
        startActivity(GoBackToMain2);
        break;
    case R.id.ibCamera:
        iCam = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
        startActivityForResult(iCam, cameraData);
        break;
    }
}

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    // TODO Auto-generated method stub
    super.onActivityResult(requestCode, resultCode, data);
    if(resultCode == RESULT_OK){
        Bundle extras = data.getExtras();
        bmp = (Bitmap) extras.get("data");
        ivCam.setImageBitmap(bmp);
    }
}

}

Xml File:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >

     <Button
        android:id="@+id/button6"
        style="?android:attr/buttonStyleSmall"
        android:layout_width="wrap_content"
        android:layout_height="28dp"
        android:text="Zurück"
        android:textSize="7dp" />

     <EditText
         android:id="@+id/editText2"
         android:layout_width="120dp"
         android:layout_height="wrap_content"
         android:layout_alignParentRight="true"
         android:layout_below="@+id/button6"
         android:layout_marginRight="50dp"
         android:layout_marginTop="20dp"
         android:ems="10" >

         <requestFocus />
     </EditText>

     <TextView
         android:id="@+id/textView2"
         android:layout_width="wrap_content"
         android:layout_height="wrap_content"
         android:layout_alignLeft="@+id/textView1"
         android:layout_below="@+id/textView1"
         android:text="eingeben und im"
         android:textSize="12dp"
         android:textAppearance="?android:attr/textAppearanceSmall" />

     <Button
         android:id="@+id/button9"
         android:layout_width="fill_parent"
         android:layout_height="40dp"
         android:layout_alignParentBottom="true"
         android:layout_alignParentLeft="true"
         android:layout_marginBottom="39dp"
         android:gravity="center"
         android:text="Rechnung hinzufügen" />

     <TextView
         android:id="@+id/textView1"
         android:layout_width="wrap_content"
         android:layout_height="wrap_content"
         android:layout_alignBottom="@+id/editText2"
         android:layout_alignParentLeft="true"
         android:layout_marginLeft="14dp"
         android:text="Wert der Rechnung"
         android:textAppearance="?android:attr/textAppearanceSmall"
         android:textSize="12dp" />

     <TextView
         android:id="@+id/textView3"
         android:layout_width="wrap_content"
         android:layout_height="wrap_content"
         android:layout_alignLeft="@+id/textView2"
         android:layout_below="@+id/textView2"
         android:text="Menü Kategorie wählen"
         android:textAppearance="?android:attr/textAppearanceSmall"
         android:textSize="12dp" />

     <Spinner
         android:id="@+id/spinner1"
         android:layout_width="120dp"
         android:layout_height="wrap_content"
         android:layout_alignLeft="@+id/editText2"
         android:layout_alignTop="@+id/textView2" />

     <ImageView
         android:id="@+id/ivCamera"
         android:layout_width="150dp"
         android:layout_height="150dp"
         android:layout_below="@+id/spinner1"
         android:layout_centerHorizontal="true"
         android:gravity="center"
         android:src="@drawable/ic_launcher" />

     <ImageButton
         android:id="@+id/ibCamera"
         android:layout_width="40dp"
         android:layout_height="40dp"
         android:layout_below="@+id/ivCamera"
         android:layout_toRightOf="@+id/textView3"
         android:src="@drawable/camera" />

     <TextView
         android:id="@+id/tvCamera"
         android:layout_width="wrap_content"
         android:layout_height="wrap_content"
         android:layout_below="@+id/ibCamera"
         android:layout_centerHorizontal="true"
         android:paddingBottom="10dp"
         android:text="Rechnung fotografieren (optional)"
         android:textSize="10dp" />

</RelativeLayout>

I'm getting no Errors in my Project.

Thanks in advance

NhatNienne
  • 937
  • 3
  • 11
  • 20
  • 1
    Is it possible you're changing the device's orientation when taking the picture so the Activity is actually being destroyed and recreated because you're not handling orientation changes? – Cruceo Aug 05 '14 at 16:37
  • I coded that all my Activitys are shown in portrait view and I'm also taking my picture in portrait view so idk – NhatNienne Aug 05 '14 at 16:41
  • possible duplicate of [Trouble working with the camera in onActivityResult](http://stackoverflow.com/questions/5279809/trouble-working-with-the-camera-in-onactivityresult) – Alex Cohn Aug 05 '14 at 20:02
  • 1
    I can't check it right now but I will check it tomorrow. Thanks for the advice. That could be the answer because currently I'm not saving anything so everytime my App starts its resetted to normal – NhatNienne Aug 05 '14 at 20:09
  • Well I found the error... I called my activity to destroy itself when it gets to the onPause Mode.. – NhatNienne Aug 07 '14 at 08:45

0 Answers0