[英]android: how to play sound in android on button click from a separate class
[英]How to run separate application from Android button click
我嘗試在我的Android應用程序中添加兩個按鈕,從單獨的兩個應用程序訂購系統和庫存系統中選擇一個應用程序。如圖所示。
我已將這兩個應用程序實現為單獨的兩個Android項目。 當我嘗試運行此應用程序時,它會直到選擇窗口正確,但是當按下一個按鈕時,模擬器會顯示“強制關閉”消息。 我已將Order系統和Inventory系統項目添加到第一個應用程序的構建路徑,然后導入它們的包(com.oms.ws和com.inv.ws)。 這可能不正確,但不知道如何做到這一點。 請幫我! 我是Android的新手。 我想使用模擬器測試這個應用程序!
這是我用來選擇應用程序的代碼。
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import com.oms.ws.*;
public class ThirdScreen extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.thirdscreen);
Button oms;
oms = (Button)findViewById(R.id.orderSystem);
oms.setOnClickListener(ordrMnagemntSys);
Button inventory;
inventory = (Button)findViewById(R.id.inventorySystem);
inventory.setOnClickListener(inventorySys);
}
private OnClickListener ordrMnagemntSys = new OnClickListener(){
public void onClick(View v) {
Intent oMs = new Intent(getApplicationContext(), com.oms.ws.TestOms.class);
startActivity(oMs);
}
};
private OnClickListener inventorySys = new OnClickListener(){
public void onClick(View v) {
Intent inven = new Intent(getApplicationContext(), com.inv.ws.TestInventory.class);
startActivity(inven);
}
};
}
謝謝!
好的,這有效
Intent LaunchIntent = getPackageManager().getLaunchIntentForPackage("org.abc");
startActivity(LaunchIntent);
將org.abc替換為您要啟動的應用程序的包名稱。
試試這個:
String app = "com.inv.ws/TestInventory";
Intent intent = new Intent(Intent.ACTION_MAIN);
intent.setComponent(ComponentName.unflattenFromString(app));
intent.addCategory(Intent.CATEGORY_LAUNCHER);
startActivity(intent);
或者用這個:
private void launchComponent(String packageName, String name){
Intent launch_intent = new Intent("android.intent.action.MAIN");
launch_intent.addCategory("android.intent.category.LAUNCHER");
launch_intent.setComponent(new ComponentName(packageName, name));
launch_intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
activity.startActivity(launch_intent);
}
在這個 answear和鏈接項目的幫助下,在我自己的應用程序中做了類似的東西。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.