因此,该应用程序应该为空,唯一要做的就是启动录音机
com.android.soundrecorder / com.android.soundrecorder.SoundRecorder
我怎样才能做到这一点?
我得到强制停止与此:
`
<uses-sdk
android:minSdkVersion="16"
android:targetSdkVersion="15" />
<application
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name=".Recorder"
android:label="@string/title_activity_recorder" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
`
和java文件
`package recorder.audio.dsaif;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
public class Recorder extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Intent LaunchIntent = getPackageManager().getLaunchIntentForPackage("com.android.soundrecorder.SoundRecorder");
startActivity(LaunchIntent);
setContentView(R.layout.activity_recorder);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.activity_recorder, menu);
return true;
}
}`
如果崩溃是由null指针异常引起的,则可能是程序包不正确和/或未安装应用程序.
这就是为什么您需要检查意图是否已给您或为null.
顺便说一句,变量名称应使用小写字母.
活动代码:
@Override
protected void onCreate(final Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
final Intent launchIntent=getPackageManager().getLaunchIntentForPackage("com.android.soundrecorder.SoundRecorder");
if(launchIntent==null)
{
Toast.makeText(this,"can't find the app to launch!",Toast.LENGTH_SHORT).show();
finish();
return;
}
launchIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(launchIntent);
finish();
}
在清单文件中,将此属性添加到活动标记,以避免显示活动的“常规”样式:
android:theme="@android:style/Theme.Dialog"