Futurescale, Inc. PureMVC Home

The PureMVC Framework Code at the Speed of Thought


Over 10 years of community discussion and knowledge are maintained here as a read-only archive.

New discussions should be taken up in issues on the appropriate projects at https://github.com/PureMVC

Pages: [1] 2
Print
Author Topic: android  (Read 39293 times)
Jiri
Jr. Member
**
Posts: 13


View Profile Email
« on: August 10, 2009, 06:13:57 »

Does anybody know if someone is porting pureMVC to Android?
Logged
denny1
Newbie
*
Posts: 1


View Profile Email
« Reply #1 on: August 10, 2009, 09:02:02 »

I am in the process of porting to Android for a client project.
Should be done in a few weeks.
Dennis
Logged
puremvc
Global Moderator
Hero Member
*****
Posts: 2871



View Profile WWW Email
« Reply #2 on: August 10, 2009, 03:03:31 »

Is a special port required?

-=Cliff>
Logged
Jiri
Jr. Member
**
Posts: 13


View Profile Email
« Reply #3 on: August 11, 2009, 09:01:39 »

I would say so, but i am really not experienced enough in Java to be correct.
I am working with PureMVC in AS3 and just started to look into Android. It would be great if i could take all my knowledge about PMVC to the new platform.
Please do keep us informed on the porting progress.

Jiri
Logged
puremvc
Global Moderator
Hero Member
*****
Posts: 2871



View Profile WWW Email
« Reply #4 on: August 11, 2009, 03:10:04 »

There are both Standard and MultiCore versions of the Java port available right now. They should both be usable on your platform. PureMVC doesn't tie into any platform specifics such as the particular mobile platform you're on, so it really should not matter.

The desire to take your framework with you as you forge into new territories is beginning to be served by the ports. Check out http://www.tripcase.com/ They have deployed an app on both Blackberry and iPhone both using PureMVC.

-=Cliff>
Logged
mikebritton
Full Member
***
Posts: 42


View Profile Email
« Reply #5 on: February 10, 2011, 09:46:50 »

I'm also trying to implement the standard version in Android, but running into problems.

My default Activity:

:
package com.britton.puremvcboilerplate;

import android.app.Activity;
import android.content.Context;
import android.os.Bundle;
import android.util.AttributeSet;
import android.view.View;

public class HomeActivity extends Activity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
   
    super.onCreate(savedInstanceState);
   
        setContentView(R.layout.main);
       
       ApplicationFacade facade = ApplicationFacade.getInstance();
       facade.startup(this);
       
    }
}

My ApplicationFacade:

:
package com.britton.puremvcboilerplate;

import org.puremvc.java.patterns.facade.Facade;

import android.app.Activity;

import com.britton.puremvcboilerplate.controller.SayHelloCommand;
import com.britton.puremvcboilerplate.controller.StartupCommand;

public class ApplicationFacade extends Facade {

/**
* Key of this facade.
*/
public static final String NAME = "ApplicationFacade";

/**
* Unique instance.
*/
private static ApplicationFacade instance = null;

public static final String STARTUP = "startup";
public static final String PREP_MODEL = "prep_model";
public static final String PREP_VIEW = "prep_view";
public static final String SAY_HELLO = "say_hello";
public static final String SAID_HELLO = "said_hello";

protected ApplicationFacade() {
super();
}

public static ApplicationFacade getInstance() {
if (instance == null) {
instance = new ApplicationFacade();
}
return instance;
}

public void startup(Activity app) {
sendNotification(STARTUP,app);
}

/* (non-Javadoc)
* @see org.puremvc.java.patterns.facade.Facade#initializeController()
*/
@Override
protected void initializeController() {

registerCommand(STARTUP, new StartupCommand());
registerCommand(SAY_HELLO, new SayHelloCommand());

super.initializeController();
}
}



Getting a null pointer exception (or something?) before I even call startup.  Should I be kicking everything off in an Activity, or somewhere else?  The Application?
Logged
mikebritton
Full Member
***
Posts: 42


View Profile Email
« Reply #6 on: February 10, 2011, 09:52:10 »

My Stack:

:
Thread [<1> main] (Suspended (exception RuntimeException))
ActivityThread.performLaunchActivity(ActivityThread$ActivityRecord, Intent) line: 2663
ActivityThread.handleLaunchActivity(ActivityThread$ActivityRecord, Intent) line: 2679
ActivityThread.access$2300(ActivityThread, ActivityThread$ActivityRecord, Intent) line: 125
ActivityThread$H.handleMessage(Message) line: 2033
ActivityThread$H(Handler).dispatchMessage(Message) line: 99
Looper.loop() line: 123
ActivityThread.main(String[]) line: 4627
Method.invokeNative(Object, Object[], Class, Class[], Class, int, boolean) line: not available [native method]
Method.invoke(Object, Object...) line: 521
ZygoteInit$MethodAndArgsCaller.run() line: 868
ZygoteInit.main(String[]) line: 626
NativeStart.main(String[]) line: not available [native method]

Logged
Tekool
Sr. Member
****
Posts: 192


View Profile WWW Email
« Reply #7 on: February 10, 2011, 10:27:46 »

Mike you can have a look at what I've did here : http://www.tekool.net/blog/2011/01/13/android-currency-converter-using-puremvc/

I use the multicore version of PureMVC, it's easier to work with an activity by PureMVC core, Android is strict regarding the coexistence of activities. This is somewhat restrictive, but could easily be explained regarding activities management by Android system (Garbage Collection). Just be careful to remove references toyour activities in PureMVC when it closes or disappear.
Logged
mikebritton
Full Member
***
Posts: 42


View Profile Email
« Reply #8 on: March 27, 2011, 06:59:26 »

Thanks for posting that.  I pursued for awhile, but put it on hold until I'd really mastered what I thought were widely understood best practices based on the SDK sample code and applications.

One thing I'm trying to decide is whether a native Android app needs a micro-architecture framework.  The scope is usually so limited relative to browser-based web applications that Activities' access to services (and a central application) seems adequate.

I may be wrong.  I guess only the future will tell.
Logged
Tekool
Sr. Member
****
Posts: 192


View Profile WWW Email
« Reply #9 on: March 28, 2011, 12:58:56 »

Hi Mike,

I agree, Android is sufficiently well thought to support a standard MVC architecture and let us hesitate on how much using a micro-architecture is needed. The problem is also that an Activity must not communicate or detain reference of another so it complicate a lot any PureMVC implementation in Android. I do not have time for the moment but I'm sure that something elegant could be made to respect the Android paradigm and implement PureMVC in a manner that at least helps in reusing components or activities.
Logged
mikebritton
Full Member
***
Posts: 42


View Profile Email
« Reply #10 on: March 28, 2011, 08:22:04 »

One thing I see in mobile, Android in particular, is poor separation of model from view.  People set data on the model from Activities, which contain GUI and kick off services and respond to user interactions in complex ways relative to the business logic.  They do too much, and know too much about each other, which imo is creating a lot of bad code as developers rush their apps to market in order to stay current.

I think a stripped-down port of puremvc would have a place, but I'm not sure Notifications would be necessary since the application already has Intents.  Perhaps Notification would extend Intent and be capable of transporting data?  Intent filters are declared in the manifest XML file, so Mediators seem unnecessary unless user interaction gets so complex in an Activity that it would benefit from mediation; but then it wouldn't be mediation, it most likely would be a view helper, accessed via composition.  Centralizing, decoupling or obfuscating the way Intents are sent would hide complexity, but introduce a learning curve to developers already struggling to learn the platform.

Commands would be useful to switch Activities, pass data to them, and persist application state.  Proxies that can also send Intents (Notifications) would be a good thing given how much more complex data manipulation in Android can become when you're dealing with cursors and native tables like raw contacts, not to mention SQLLite.

It's an interesting conversation. 

 
Logged
puremvc
Global Moderator
Hero Member
*****
Posts: 2871



View Profile WWW Email
« Reply #11 on: March 29, 2011, 09:11:50 »

Hi Mike,

I'm not 100% sure what Intents are and how they completely change the game, but I'd be surprised if they totally invalidated the PureMVC premise. Looking at the info here: http://developer.android.com/reference/android/content/Intent.html ...they sort've seem like configurable binding to me, only the result is code being run rather than properties being set. That's something you can take or leave in Flex, is the same true here? That is, in Flex, I still do binding, but only within an component to wire everything together. I don't go binding things all across the app. I use notifications to move data between components and the rest of the system.

In iOS, many people said that MVC was already built in so it was silly to port PureMVC to it. But reports from people who use it there seem to indicate it's perfectly fine to choose one way to move messages around as opposed to another. If you were building an app for iOS and android (and didn't want to use AIR), then you'd have no choice but to have completely different projects where the services and view components are declared in a different way, the language is different, etc. But the overall architecture shouldn't have to change if you're able to use PureMVC. The actors and their roles and responsibilities should be able to remain the same for the most part. Reusable architecture. And if you're coming from a PureMVC environment, learning a new environment is made a lot easier when the architecture choices remain constant. There is value in that.

Every platform is going to have it's special sauce for getting things done, but the PureMVC philosophy has been not to buy the framework itself into those bells and whistles. So I don't think we'd want to go extending Intent and changing the way the framework operates specially for the android platform. Lots of Flex people said PureMVC wasn't as powerful as it could be because it didn't leverage binding. But because it didn't, it was portable to all sorts of other platforms. So 'power' is relative. If you don't give a hoot about other platforms, then it may seem too abstract to be useful in your chosen environment of the moment. But when you need to port an app to another platform, you may find it comforting that the big picture didn't have to change.

I'm planning to dive into android soon myself, and would love to understand how and why things are so different. I definitely would like to hear what things stand in the way of PureMVC working as expected in android.

-=Cliff>
Logged
mikebritton
Full Member
***
Posts: 42


View Profile Email
« Reply #12 on: March 29, 2011, 11:03:25 »

I definitely get the portable architecture angle, and agree.  I'm looking more closely at the currency converter (PureMVC Multicore, Java) to wrap my head around what it's doing.  Maybe I'll have more thoughts about Intents at that point.

One intial problem to solve, one I ran into with the Flex hero SDK as well: when an Activity closes, its Mediator should be removed.  Same goes for starting an Activity.  This is a best practice anyway, but in the case of mobile development it's mandatory. 

I did this in a Command for the entire Flex application and it worked well, so I'm curious to see how it works in native Android.
Logged
puremvc
Global Moderator
Hero Member
*****
Posts: 2871



View Profile WWW Email
« Reply #13 on: March 30, 2011, 07:37:13 »

One intial problem to solve, one I ran into with the Flex hero SDK as well: when an Activity closes, its Mediator should be removed.  Same goes for starting an Activity.  This is a best practice anyway, but in the case of mobile development it's mandatory.

You can just have the Mediator listen to the view component for Event.REMOVED_FROM_STAGE and handle it by having the mediator remove itself. I don't know if that will work for an Activity or not, but surely there's some analog of it. No need to involve any other actors in the process.

-=Cliff>
Logged
Tekool
Sr. Member
****
Posts: 192


View Profile WWW Email
« Reply #14 on: March 31, 2011, 08:52:14 »

Sorry, I do not have so much time to participate into the discussion.

What makes it difficult with Android is that the system could decide to remove an Activity without the application have any knowledge of it at any moment. In fact an event is fired when possible but if the system memory is near full, to be sure that Activities will not consume still more memory to process this event the system could simply remove the Activity silently.

As the main problem was to be sure not to create garbage collection problem with unwanted references to and from activities I chosen multicore. So when I need to launch an Activity I simply check for its existence and re-create it if needed. To make the things neat anyway I've included this code in each Activity :

:
    /**
     * Called (or not called) when the activity is destroyed by the Android
     * system.
     */
    @Override   
    public void onDestroy()
    {
    super.onDestroy();
   
    ActivityFacade.removeCore( ActivityNames.MyActivityName);   
    }

You can find this here : https://github.com/tekool/puremvc-android-currency-converter/blob/master/src/org/puremvc/java/demos/android/currencyconverter/preferences/PreferencesActivity.java

Using multicore helps in using Intents. I suppose that building a Pipe utility specifically designed for Android over intents mechanism could lead to a neat solution (I think to replace Message with Intents args or something like that). I do not have time for this at the moment but this could be an idea that do not need to modify PureMVC for Android, only this utility.



Logged
Pages: [1] 2
Print