Daniel online
- Forum-Beiträge: 282
18.05.2011, 12:53:08 via Website
18.05.2011 12:53:08 via Website
Ich bin hier schon wieder am verzweifeln.
Ich ruf eine Activity über startActivityForResult auf, beim beenden wird aber onActivityResult in der ursprünglichen Activity nicht aufgerufen.
Obwohl ich alles exakt genauso mache wie in einem anderen Projekt, wo es funktioner...
HauptActivity
zweite Activity
Ich hoffe ihr könnt mir helfen
Ich ruf eine Activity über startActivityForResult auf, beim beenden wird aber onActivityResult in der ursprünglichen Activity nicht aufgerufen.
Obwohl ich alles exakt genauso mache wie in einem anderen Projekt, wo es funktioner...
HauptActivity
1package de.Daniel.home;
2
3import android.app.Activity;
4import android.content.Intent;
5import android.os.Bundle;
6import android.preference.PreferenceManager.OnActivityResultListener;
7import android.view.View;
8import android.widget.Button;
9import android.widget.Toast;
10
11public class kitchen_main extends Activity {
12 /** Called when the activity is first created. */
13 @Override
14 public void onCreate(Bundle savedInstanceState)
15 {
16 super.onCreate(savedInstanceState);
17 setContentView(R.layout.kitchen_main);
18 }
19
20
21 public void onClick(View v)
22 {
23 switch(v.getId())
24 {
25 case R.id.main_b1:
26 {
27 Intent i = new Intent(this, setAlarm.class);
28 i.putExtra("id", (R.id.main_b1));
29 startActivityForResult(i, 5);
30 break;
31 }
32 case R.id.button1:
33 {
34 finish();
35 break;
36 }
37
38 }
39 }
40 public void onActivtiyResult(int requestCode, int resultCode, Intent data)
41 {
42 Toast.makeText(this, ""+resultCode, 1000).show();
43 if(resultCode==Activity.RESULT_OK)
44 {
45 //Daten auslesen
46 Bundle extra = getIntent().getExtras();
47 int id = extra.getInt("id"); // Id des Buttons
48 int hour = extra.getInt("hour");
49 int min = extra.getInt("min");
50 int seconds = extra.getInt("seconds");
51 //Daten auf View anzeigen
52 Button button = (Button)findViewById(id);
53 button.setText(""+hour+":"+min+":"+seconds);
54 Toast.makeText(this,"Timer:"+ hour+min+seconds+" "+id, 1000).show();
55 }
56 }
57
58}
2
3import android.app.Activity;
4import android.content.Intent;
5import android.os.Bundle;
6import android.preference.PreferenceManager.OnActivityResultListener;
7import android.view.View;
8import android.widget.Button;
9import android.widget.Toast;
10
11public class kitchen_main extends Activity {
12 /** Called when the activity is first created. */
13 @Override
14 public void onCreate(Bundle savedInstanceState)
15 {
16 super.onCreate(savedInstanceState);
17 setContentView(R.layout.kitchen_main);
18 }
19
20
21 public void onClick(View v)
22 {
23 switch(v.getId())
24 {
25 case R.id.main_b1:
26 {
27 Intent i = new Intent(this, setAlarm.class);
28 i.putExtra("id", (R.id.main_b1));
29 startActivityForResult(i, 5);
30 break;
31 }
32 case R.id.button1:
33 {
34 finish();
35 break;
36 }
37
38 }
39 }
40 public void onActivtiyResult(int requestCode, int resultCode, Intent data)
41 {
42 Toast.makeText(this, ""+resultCode, 1000).show();
43 if(resultCode==Activity.RESULT_OK)
44 {
45 //Daten auslesen
46 Bundle extra = getIntent().getExtras();
47 int id = extra.getInt("id"); // Id des Buttons
48 int hour = extra.getInt("hour");
49 int min = extra.getInt("min");
50 int seconds = extra.getInt("seconds");
51 //Daten auf View anzeigen
52 Button button = (Button)findViewById(id);
53 button.setText(""+hour+":"+min+":"+seconds);
54 Toast.makeText(this,"Timer:"+ hour+min+seconds+" "+id, 1000).show();
55 }
56 }
57
58}
zweite Activity
1package de.Daniel.home;
2
3import android.app.Activity;
4import android.content.Intent;
5import android.os.Bundle;
6import android.view.View;
7import android.widget.EditText;
8import android.widget.Toast;
9
10public class setAlarm extends Activity
11{
12
13
14
15
16 public void onCreate(Bundle savedInstanceState)
17 {
18 super.onCreate(savedInstanceState);
19 setContentView(R.layout.setalarm);
20
21
22 }
23
24 public void onClick(View v)
25 {
26 if(v.getId()==R.id.set_b1)
27 {
28 Bundle extra = getIntent().getExtras();
29 int id = extra.getInt("id"); //Id des Buttons
30
31 NumberPicker hour = (NumberPicker)findViewById(R.id.set_picker_hour);
32 NumberPicker min = (NumberPicker)findViewById(R.id.set_picker_min);
33 NumberPicker seconds = (NumberPicker)findViewById(R.id.set_picker_sec);
34 EditText edit = (EditText)findViewById(R.id.set_edit1);
35 final Intent intent = new Intent();
36 intent.putExtra("hour", hour.getCurrent());
37 intent.putExtra("min", min.getCurrent());
38 intent.putExtra("seconds", seconds.getCurrent());
39 intent.putExtra("name", edit.getText());
40 intent.putExtra("id", id); //
41 Toast.makeText(this,""+ hour.getCurrent()+min.getCurrent()+seconds.getCurrent()+edit.getText()+id, 1000).show();
42 setResult(Activity.RESULT_OK, intent);
43 finish();
44 }
45 }
46}
2
3import android.app.Activity;
4import android.content.Intent;
5import android.os.Bundle;
6import android.view.View;
7import android.widget.EditText;
8import android.widget.Toast;
9
10public class setAlarm extends Activity
11{
12
13
14
15
16 public void onCreate(Bundle savedInstanceState)
17 {
18 super.onCreate(savedInstanceState);
19 setContentView(R.layout.setalarm);
20
21
22 }
23
24 public void onClick(View v)
25 {
26 if(v.getId()==R.id.set_b1)
27 {
28 Bundle extra = getIntent().getExtras();
29 int id = extra.getInt("id"); //Id des Buttons
30
31 NumberPicker hour = (NumberPicker)findViewById(R.id.set_picker_hour);
32 NumberPicker min = (NumberPicker)findViewById(R.id.set_picker_min);
33 NumberPicker seconds = (NumberPicker)findViewById(R.id.set_picker_sec);
34 EditText edit = (EditText)findViewById(R.id.set_edit1);
35 final Intent intent = new Intent();
36 intent.putExtra("hour", hour.getCurrent());
37 intent.putExtra("min", min.getCurrent());
38 intent.putExtra("seconds", seconds.getCurrent());
39 intent.putExtra("name", edit.getText());
40 intent.putExtra("id", id); //
41 Toast.makeText(this,""+ hour.getCurrent()+min.getCurrent()+seconds.getCurrent()+edit.getText()+id, 1000).show();
42 setResult(Activity.RESULT_OK, intent);
43 finish();
44 }
45 }
46}
Ich hoffe ihr könnt mir helfen
Empfohlener redaktioneller Inhalt
Mit Deiner Zustimmung wird hier ein externer Inhalt geladen.
Mit Klick auf den oben stehenden Button erklärst Du Dich damit einverstanden, dass Dir externe Inhalte angezeigt werden dürfen. Dabei können personenbezogene Daten an Drittanbieter übermittelt werden. Mehr Infos dazu findest Du in unserer Datenschutzerklärung.