Legacy Application support?

35 views
Skip to first unread message

Mingfai Ma

unread,
Jun 16, 2013, 12:21:26 PM6/16/13
to tran...@googlegroups.com
hi,

There is legacy Activity support, but there seems to be no legacy Application support.

My use case is, I tried to put ACRA (http://acra.ch/) to my project. It requires putting annotation at the Application, and then call ACRA.init(this). It's init() code is as follows:
 public static void init(Application app) {
    ...
        mReportsCrashes = mApplication.getClass().getAnnotation(ReportsCrashes.class);

So it really expect the Application as argument, and the app has to have the @ReportsCrashes annotation. So either I have to use my application class, or the Transfuse has to allow me to add annotation to the generated application class. Should i fire a new feature issue? 

This feature is not important to me.if i really need to use ACRA, there should be ways to initialise it programmatically without the annotation (from my first glance at the init() source code). However, I think it's good to mention this use case and it's good for Transfuse to be able to work well with other frameworks/libraries.




John Ericksen

unread,
Jun 16, 2013, 12:39:00 PM6/16/13
to tran...@googlegroups.com
Legacy Applications are also supported (Service, BroadcastReceivers as well).  You can either declare them manually in the manifest, or you can annotate your Application:

@Application
@ReportsCrashes(formKey = "", formUri = "http://www.yourselectedbackend.com/reportpath")
public class MyApplication extends Application {
  @Override
  public void onCreate() {
    // The following line triggers the initialization of ACRA
    super.onCreate();
    ACRA.init(this);
  }
}

Enhancing the Application can be a bit tricky and a current rough spot in the framework.  Make sure you watch what happens to your AndroidManifest.xml, and if Transfuse adds a second Application tag, you may need to do a manual merge.

I need to update the docs with the other legacy components.  By the way, I updated the docs to reflect the changes to 0.2.0 (@Named, Scopes, etc).

You can also use the enhanced Transfuse classes with Acra:

@Application
@ReportsCrashes(formKey = "", formUri = "http://www.yourselectedbackend.com/reportpath")
public class MyApplication {
  @Inject Application application;
  @OnCreate
  public void setupAcra() {
    ACRA.init(application);
  }
}

I've been thinking about a plugin architecture for Transfuse so you can define these things in the Module in 1 line like this:

@TransfuseModule
@ReportsCrashes(formKey = "", formUri = "http://www.yourselectedbackend.com/reportpath")
public class ModuleClass{}

Thoughts?

Mingfai

unread,
Jun 16, 2013, 1:03:18 PM6/16/13
to John Ericksen, tran...@googlegroups.com
Thanks. Let me focus on the first part about how legacy Application support work first.

I thought there is no legacy Application support because I see the generated Application class doesn't have the annotation, e.g.

import android.app.Application;
@org.androidtransfuse.annotations.Application
@Debug
public class HelloApp extends Application {
}

The generated class looks like the following:

@Generated(value = "org.androidtransfuse.TransfuseAnnotationProcessor", date = "2013-06-17T00:58+0800")
public class HelloAppApplication
    extends Application
    implements ContextScopeHolder
{

    private Scope scope$0 = new ConcurrentDoubleLockingScope();

    @Override
    public void onCreate() {
        super.onCreate();
        Scopes scopes$0 = Transfuse$ScopesUtil.getInstance();
        HelloApp helloApp$0 = new HelloApp();
    }

    @Override
    public Scope getScope() {
        return scope$0;
    }

}

And i suppose my @Debug annotation is not included in the Application, right?

I pushed the test code to my hello-transfuse repository as test2.



--
You received this message because you are subscribed to the Google Groups "Transfuse" group.
To unsubscribe from this group and stop receiving emails from it, send an email to transfuse+...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

John Ericksen

unread,
Jun 16, 2013, 1:21:04 PM6/16/13
to tran...@googlegroups.com, John Ericksen
This is very strange.  I thought I implemented legacy Application support, but it seems to be missing.  Would you like to open a feature issue?

Looking deeper at Acra, it may be a hassle getting it to work with Transfuse.  I may need to contact the developers to see what we can do about a plugin or better integration between the two libraries.

Specifically, Acra requires the Application to be annotated with @ReportsCrashes (as you know) and doesn't seem to allow a manual setup.  If we had something like the following it would be fine:

ACRA.init(application, new ReportsCrashesConfig("key", "url");

ACRA{
    public static void init(Application app, ReportsCrashesConfig config)
}

For the time being you can just use a regular Application and enter it manually into the AndroidManifest.xml.

Mingfai

unread,
Jun 16, 2013, 1:26:17 PM6/16/13
to John Ericksen, tran...@googlegroups.com
On Mon, Jun 17, 2013 at 1:21 AM, John Ericksen <johnc...@gmail.com> wrote:
This is very strange.  I thought I implemented legacy Application support, but it seems to be missing.  Would you like to open a feature issue?

sure


For the time being you can just use a regular Application and enter it manually into the AndroidManifest.xml.

for now, I will just don't use ACRA if Transfuse doesn't support it. :-)

There might be a lot of works to maintain different plugin for other frameworks. See my comment to another point:


On Mon, Jun 17, 2013 at 12:39 AM, John Ericksen <johnc...@gmail.com> wrote:

I've been thinking about a plugin architecture for Transfuse so you can define these things in the Module in 1 line like this:

@TransfuseModule
@ReportsCrashes(formKey = "", formUri = "http://www.yourselectedbackend.com/reportpath")
public class ModuleClass{}

Thoughts?

personally, I prefer to have a coding style similar to the "normal" Android development, at least before Transfuse become a dominating Android IoC framework. This makes it easier for people with normal Android experience to understand the code. 

take ACRA as example, people will read its website for doc. ACRA's doc won't talk about how to configure in Transfuse. And people expect the @ReportsCrashes be put at the Application, and as the application class is generated, the closest one is to put it next at the @Application class.

Indeed, personally, i would prefer to have an option to disable the AndroidManifest.xml generation, as a optional feature to make it easy for adoption. When people get used to the Transfuse way and comfortable with it, they won't maintain their AndroidManifest.xml by hand.

John Ericksen

unread,
Jun 16, 2013, 1:47:35 PM6/16/13
to tran...@googlegroups.com, John Ericksen
Easier than I expected to implement.

This should work for you now in 0.2.2-SNAPSHOT:

@Application
@ReportsCrashes(formKey = "", formUri = "http://www.yourselectedbackend.com/reportpath")
public class MyApplication extends Application {
  @Override
  public void onCreate() {
    // The following line triggers the initialization of ACRA
    super.onCreate();
    ACRA.init(this);
  }
}

If you want Transfuse to manage the manifest for you.

If you don't want Transfuse to manage the manifest, you can always add the Application manually and not annotate the class.  I am open to adding a feature to turn off Manifest generation, but I fear that will actualy make things more complicated for the end developer.
Reply all
Reply to author
Forward
0 new messages