| Author |
Message |
plusminus Site Admin


Joined: 14 Nov 2007 Posts: 2660 Location: College Park, MD
|
|
| Back to top |
|
 |
|
|
 |
venkat Senior Developer

Joined: 27 Nov 2007 Posts: 152 Location: India
|
Posted: Mon Feb 04, 2008 12:47 pm Post subject: |
|
|
thanks for your replay plusminus,
actually i need to pass data "from activity to subacitivity" not "subactivity to activity"  _________________ Regards,
Venkat. |
|
| Back to top |
|
 |
plusminus Site Admin


Joined: 14 Nov 2007 Posts: 2660 Location: College Park, MD
|
|
| Back to top |
|
 |
venkat Senior Developer

Joined: 27 Nov 2007 Posts: 152 Location: India
|
Posted: Mon Feb 04, 2008 1:09 pm Post subject: |
|
|
Thank you very much Plus minus ..
i will try it now and let you know if i have any doubt. _________________ Regards,
Venkat. |
|
| Back to top |
|
 |
venkat Senior Developer

Joined: 27 Nov 2007 Posts: 152 Location: India
|
Posted: Mon Feb 04, 2008 1:26 pm Post subject: |
|
|
it works
thank you very much..  _________________ Regards,
Venkat. |
|
| Back to top |
|
 |
bavarol Experienced Developer

Joined: 10 Dec 2007 Posts: 52
|
Posted: Thu May 29, 2008 10:51 am Post subject: |
|
|
Hi
I have understood the way you pass primitive Type objects but it's not so clear how it can pass a more complex Object between Activities.
It should be something like this, shouldn't it?
| Java: |
Intent intent = new Intent(InvokingActivity.this, InvokedActivity.class);
intent.putExtra("anObject",object) ;
startSubActivity(intent, 0); |
| Java: |
Bundle bundle = this.getIntent().getExtras();
if ( bundle != null ) {
Object object = bundle.get("anObject"); <-- Error
} |
However I get an error :
| Code: | | The Method get(String) is undefined for type Bundle |
=============================================
How can I pass objects between activities?
Cheers
P.S.:I have the SDK m3rc22a. |
|
| Back to top |
|
 |
|
|
 |
feelingAndroid Once Poster

Joined: 26 May 2008 Posts: 1
|
Posted: Wed Jul 02, 2008 4:23 am Post subject: showAlert problem |
|
|
hi plusminus,
This line is something wrong :showAlert("SubActivity returned",0, "ReturnValue: " + data,
"OK", false); Eclipse shows as follows:
The method showAlert(CharSequence, int, CharSequence, CharSequence, boolean) in the type
ApplicationContext is not applicable for the arguments (String, String, String, boolean)
Last edited by feelingAndroid on Fri Jul 04, 2008 4:58 am; edited 1 time in total |
|
| Back to top |
|
 |
mrdanger Freshman

Joined: 17 Jun 2008 Posts: 9 Location: Hamburg, Germany
|
Posted: Thu Jul 03, 2008 6:16 pm Post subject: |
|
|
Hello everbody,
i get the failure message
"... List Views can't have unspecified size"
Can you help me?
About my Probleme and the solution
Google Discussion |
|
| Back to top |
|
 |
darolla Master Developer


Joined: 25 Sep 2008 Posts: 227 Location: Dortmund, Germany
|
Posted: Tue Dec 30, 2008 1:40 pm Post subject: |
|
|
thanks for this. but in the actual sdk there are some changes.
here comes the clue
this way the subactivity is called:
| Java: |
Intent intent = new Intent();
intent.setClass(this, SubActivity.class);
startActivityForResult(intent, 1234);
|
this way the "result" is given back to the calling activity
| Java: |
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
Log.d(TAG, "" + requestCode);
Log.d(TAG, "" + resultCode);
Log.d(TAG, "" + data.getStringExtra( "result" ) );
}
|
this way the "result" is send in the subactivity
| Java: |
Button someExitButton = (Button)findViewById(R.id.someExitButton);
someExitButton.setOnClickListener(new OnClickListener(){
public void onClick(View view) {
Intent data = new Intent();
data.putExtra( "result", theResultString );
setResult( RESULT_OK, data );
finish();
}
});
|
greetings,
darolla |
|
| Back to top |
|
 |
Artur79 Developer

Joined: 26 Sep 2008 Posts: 26
|
Posted: Thu Jan 15, 2009 12:57 pm Post subject: |
|
|
a line (adjusted to orginal code)
| Java: |
intent.setClass(this, SubActivityWithResult.class);
|
doesn't work |
|
| Back to top |
|
 |
ioRek Freshman

Joined: 22 Jun 2009 Posts: 9
|
Posted: Mon Jun 22, 2009 3:36 pm Post subject: import |
|
|
| what's the import needed for showalert, still can't find it RHA |
|
| Back to top |
|
 |
xenon Freshman

Joined: 11 Jun 2009 Posts: 2
|
Posted: Thu Jun 25, 2009 2:09 pm Post subject: |
|
|
Unfortunately, like Artur79 already mentioned, the following line doesn't work:
| Java: |
intent.setClass(this, SubActivityWithResult.class);
|
Error message
| Quote: |
The method setClass(Context, Class<?>) in the type Intent is not applicable for the arguments (new View.OnClickListener(){}, Class<SubActivityWithResult>) MainActivity.java subactivitywithresult/src/com/example/subactivitywithresult line 28 Java Problem
|
Someone knows how to fix this? |
|
| Back to top |
|
 |
Erykgecko Junior Developer

Joined: 16 May 2009 Posts: 19
|
Posted: Sun Jul 19, 2009 8:33 pm Post subject: |
|
|
ok, I have an activity that calls a subactivity, based on this code. so thats fine, it all works, i can call my subactivity, select something and it passes the data back to my activity... Groovy,
however, if i switch to my subactivity, then decide i don't want to select anything, i want to just return to my normal activity, i hit the back button on my phone.
this breaks my app... and i get the standard force close. So I figured i would try adding onStop() and onDestroy() to my sub activity, and in them just called the finish() that should pass it back to the main activity.. alas it will not work...
I'm sure theres a really simple answer i'm missing, but I can't seem to figure it out...
any suggestions?
-edit-
OK, Figured it,
| Java: | @Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
if(keyCode == KeyEvent.KEYCODE_BACK){
data.putExtra("blah", "");
filebrowser.this.setResult(SUCCESS_RETURN_CODE,data);
filebrowser.this.finish();
super.onKeyDown(keyCode, event);
}
return true;
} |
|
|
| Back to top |
|
 |
luthepa1 Junior Developer

Joined: 14 Oct 2009 Posts: 11
|
Posted: Wed Oct 28, 2009 8:46 am Post subject: Help. App crashes and dont understand why? |
|
|
Ok I'm a noob who cant understand why my app crashes with a "Force Close" exception. I basically am following this post for learning how to work with sub-activities and return data from that sub-activity. I can get it to work using a test method by just returning a string value in quotes. But when I add
| Java: | EditText txtWorkoutName = (EditText)findViewById(R.id.newTxtName); |
it will crash even though I dont even pass the txtWorkoutName variable back through the intent.
Here is what works
| Java: |
public class neweditworkout extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//Inflate View
setContentView(R.layout.neweditworkout);
final Button btnSelect = (Button)findViewById(R.id.newButtonSelect);
btnSelect.setOnClickListener(new View.OnClickListener() {
//@Override
public void onClick(View v) {
//EditText txtWorkoutName = (EditText)findViewById(R.id.newTxtName);
Intent data = new Intent();
data.putExtra("result", "TEST_DATA");
neweditworkout.this.setResult(RESULT_OK, data);
neweditworkout.this.finish();
}
});
}
}
|
And here is what cause the application the crash when clicking the button
| Java: |
public class neweditworkout extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//Inflate View
setContentView(R.layout.neweditworkout);
final Button btnSelect = (Button)findViewById(R.id.newButtonSelect);
btnSelect.setOnClickListener(new View.OnClickListener() {
//@Override
public void onClick(View v) {
EditText txtWorkoutName = (EditText)findViewById(R.id.newTxtName);
Intent data = new Intent();
data.putExtra("result", "TEST_DATA");
neweditworkout.this.setResult(RESULT_OK, data);
neweditworkout.this.finish();
}
});
}
}
|
And here is the onActivityResult from my main activity
| Java: |
// Listen for results from sub-activities.
//@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
Toast.makeText(this, "Returned: "+data.getStringExtra("result"), Toast.LENGTH_LONG).show();
}
|
As I say, just uncommenting that one line causes the crashes.
Thanks in advance, Paul. |
|
| Back to top |
|
 |
luthepa1 Junior Developer

Joined: 14 Oct 2009 Posts: 11
|
Posted: Thu Oct 29, 2009 7:21 am Post subject: |
|
|
I found the problem. Please excuse my previous post. My findViewById was pointing to a TextView instead of a EditText view. All works now  |
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum You cannot attach files in this forum You can download files in this forum
|
© 2007, Android Development Community
All rights reserved.
Powered by phpBB.
|