Android - pass sparkCloud object between activities


I’m primarily an embedded developer, but am trying to develop an Android app for my application. I have got a small hang of activities and intents. I am having difficulty trying to pass a SparkCloud object from one activity to another.

The aim is to attempt the login in one activity, and then switch to another activity and pass the cloud instance to that. I could also pass in the credentials between activities instead as they are native datatypes. I feel like the former implementation is more ideal as it is a piece of information the second activity needn’t worry about.

Any help and opinions would be appreciated.


You don’t need to pass credentials. I thought so at first to, but once your user logs in he’s logged in for each activity. So you can just grab a new cloud by calling ParticleSDK.getCloud

1 Like

Thanks a lot for that ! That just made my code a lot simpler. For reference, here is an instance of the cloud object I created in my second activity for usage inside that activity which works now.

SparkCloud localSparkCloud = SparkCloud.get(SecondActivity.this);

1 Like

I believe SparkCloud.get() has been deprecated though. It still seems to work, but you might want to switch it up to ParticleSDK.getCloud();

I was following the instructions on the Particle Reference Manual for Android. That shows 0.1.3 which still uses the Spark APIs. I’ll switch it over to the new rev as you said to be forward compatible.

Thanks for all the help.