Hi Andy,

 

Following your advice I’m using the custom application below. It has a
public property (layout) which I use to add to the main Activity. The
problem is this property is always null there. Application is bein used in
main Activity OnCreate event like this:

 

      var ctrl = new MyApplication();

      SetContentView(ctrl.layout);

 

MyApplication implementation:

 

  [Application]

  public class MyApplication : Application

  {

    public RelativeLayout layout { get ; set; }

 

    public MyApplication(IntPtr handle)

      : base(handle)

    {

    }

 

    public MyApplication()

      : base()

    {

    }

 

    public override void OnCreate()

    {

      base.OnCreate();

 

      MyImageView i = new MyImageView(this.ApplicationContext);

      MyImageView i2 = new MyImageView(this.ApplicationContext);

 

      layout = new RelativeLayout(this);

 

      layout.AddView(i, new
RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.FillParent,
RelativeLayout.LayoutParams.FillParent));

 

      RelativeLayout.LayoutParams lp = new RelativeLayout.LayoutParams(400,
400);

      lp.LeftMargin = 100;

      lp.TopMargin = 100;

      layout.AddView(i2, lp);

    }

  }

 

Do you have any idea how should I use this property in the parent Activity?
I tried doing the same in Java for Android and can’t even get the onCreate
event firing there. 

 

 

Best Regards,

Narcís Calvet

Steema Software

 <http://www.steema.com/> http://www.steema.com

 <http://twitter.com/SteemaSoftware> http://twitter.com/SteemaSoftware

 <https://www.facebook.com/SteemaSoftware>
https://www.facebook.com/SteemaSoftware

 

From: monodroid-boun...@lists.ximian.com
[mailto:monodroid-boun...@lists.ximian.com] On Behalf Of Andrew Sinclair
Sent: dimarts, 19 / juliol / 2011 14:01
To: 'Discussions related to Mono for Android'
Subject: Re: [mono-android] Getting objects from an intent

 

Narcís,

 

You can derive from Android.App.Application, this will give you a singleton
class which can hold global application state. For such a class you need to
use the [Application] attribute - this will add the appropriate entry in the
AndroidManifest.xml.

 

Storing the instance of an activity doesn’t seem much use in Android because
activities are created and destroyed regularly by the system in accordance
with the activity lifecycle. So if you want to access a property of one
activity from another activity then there’s a very good chance that the
“target” activity will be invalid.

 

This might be different with activity groups, I haven’t used them, but in
general I’ve found it best to store data in an instance-independent manner.

 

The same things applies with Views. Suppose you had 2 views within an
activity that both cause another activity to be shown, and you wanted to
remember which view had triggered this new activity. Within Windows you
might have a member variable of the calling activity called _triggeringView
and you’d access this when you returned to the original activity. With
Android that’s no use because you have to assume that the original activity
will be destroyed during the whole process. One way around this is to store
something like “triggering view was the 2nd view” at the application level
or as part of the saved state bundle in the activity. So you’re just storing
an integer.

 

Clear as mud? I hope it helps anyway, the implications of the activity life
cycle are very far reaching if you are porting an application from, for
example, .NETCF.

 

Andy

 

 

From: monodroid-boun...@lists.ximian.com
[mailto:monodroid-boun...@lists.ximian.com] On Behalf Of Narcís Calvet
Sent: 19 July 2011 12:28
To: 'Discussions related to Mono for Android'
Subject: Re: [mono-android] Getting objects from an intent

 

Searching a little bit and looking for what’s available in IParcelable it
seems it is not complete in Mono for Android so I guess I should discard
this option. Any other ideas?

 

Thanks!

 

 

Best Regards,

 

Narcís Calvet

Steema Software

http://www.steema.com <http://www.steema.com/> 

http://twitter.com/SteemaSoftware

https://www.facebook.com/SteemaSoftware

 

 

From: monodroid-boun...@lists.ximian.com
[mailto:monodroid-boun...@lists.ximian.com] On Behalf Of Narcís Calvet
Sent: dimarts, 19 / juliol / 2011 11:04
To: 'Discussions related to Mono for Android'
Subject: [mono-android] Getting objects from an intent

 

Hello,

 

I have created a custom activity which I use in an ActivityGroup using
Intents. How can I get the instance of my custom activity the intent has
created to be able to use its properties and methods? I read I may need to
use Serializable or Parcelable interfaces but haven’t succeed on this so
far. Monodroid examples on this would be great!

 

Thanks in advance.

 

 

Best Regards,

 

Narcís Calvet

Steema Software

http://www.steema.com <http://www.steema.com/> 

http://twitter.com/SteemaSoftware

https://www.facebook.com/SteemaSoftware

 

 

 

_______________________________________________
Monodroid mailing list
Monodroid@lists.ximian.com

UNSUBSCRIBE INFORMATION:
http://lists.ximian.com/mailman/listinfo/monodroid

Reply via email to