如何从图书馆开始主要活动? [英] How to start main activity from a library?

查看:165
本文介绍了如何从图书馆开始主要活动?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用的一个项目,和图书馆项目,发展我的Andr​​oid应用程序。这两个项目都在其中活动。如果我目前在A计划,那么很容易只是刚刚导入它开始在库项目的活动。但是,我不知道如何开始一个活动项目中的一个,如果我从库项目活动的到来。我想,因为我将使用它的多个应用程序,以使独立于项目A的包名的库项目。如何做到这一点任何想法?谢谢你。

I am using a Project A, and a library project to develop my Android app. Both of these projects have activities in them. If I am currently in Project A, then it is easy to just start an activity in the library project by just importing it. However, I'm not sure how to start an Activity in Project A if I am coming from an activity in the library project. I'm trying to make the library project independent of the package name of the Project A since I will be using it for multiple apps. Any ideas on how to do this? Thanks.

推荐答案

我相信这是最简单的答案:你需要一个对象,它存在于库,你可以在你的项目延长

I believe this is to be the simplest answer: you'll need an object which exists in the library, which you can extend in your project.

想象一下,你的图书馆有哪些你ProjectApplication延伸LibraryApplication。该LibraryActivity可致电:

Imagine that your library has a LibraryApplication which your ProjectApplication extends. The LibraryActivity can call:

((LibraryApplication)getApplication()).startNewActivity(this, "goHome")

您ProjectApplication实现这种新方法:

Your ProjectApplication implements this new method:

public void startNewActivity(Context context, String action) {
    if("goHome".equals(action)) {
        startActivity(context, ProjectHomeActivity.class);
    }
}

这篇关于如何从图书馆开始主要活动?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆