简体   繁体   English

使用库将两个项目合并为一个

[英]merge two projects in one using library

I have two android project, for example i want to make my first project as a library and make a button in the second ^project that help me to access to the first project library. 我有两个android项目,例如,我想将第一个项目制作为库,并在第二个^ project中创建一个按钮,以帮助我访问第一个项目库。 my question is how to code the access to the library ? 我的问题是如何编码对库的访问?

You say as a Library but i think you mean launch another Activity. 您说的是图书馆,但我认为您的意思是发起另一个活动。

launch(getApplicationContext(), "com.example.myactivity");

And this is the method to launch another Activity 这是启动另一个活动的方法

public static void launch(Context context, String packageName) {
        Intent intent = context.getPackageManager().getLaunchIntentForPackage(packageName);

        if (intent == null) {
            intent = new Intent(Intent.ACTION_VIEW);
            intent.setData(Uri.parse(packageName));
        }
        intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        context.startActivity(intent);
    }

Yes you replace with your package name and this method is quite broad, it finds any activity designated as a main activity. 是的,您可以用程序包名称替换它,并且此方法非常广泛,它可以找到指定为主要活动的任何活动。 Which is fine unless you have multiple activities listed like so 除非您列出了多个活动,否则就可以了

      <activity
                android:name=".activity.WelcomeActivity"
                android:label="@string/app_name"
                android:theme="@style/AppTheme"
                android:windowSoftInputMode="stateHidden|adjustResize" >
                <intent-filter>
                    <action android:name="android.intent.action.MAIN" />
                    <category android:name="android.intent.category.LAUNCHER" />
                </intent-filter>
            </activity>
 <activity 
android:name=".activity.MainActivity"> 
 <intent-filter>
         <action android:name="android.intent.action.MAIN" />
          <category android:name="android.intent.category.LAUNCHER" />
    </intent-filter>
            </activity>

in this case it will find both activities, but for your needs i think just the package name will do 在这种情况下,它会找到两个活动,但是对于您的需求,我认为仅包名即可

for this in the manifest you do not need to make any changes. 为此,您无需进行任何更改。 can pick any app from the market and find its package and if it is installed it will launch it 可以从市场上挑选任何应用程序并找到其软件包,如果已安装,它将启动它

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM