سلام
وقتی برنامه رو خودم اجرا می کنم مشکلی نداره و درست اجرا میشه ولی در استارت آپ خطای Unfortunately MyFirstApp has stopped میاد
می خوام ببینم مشکل از کدهای زیره یا نه؟manifest:
این هم در کلاس MyActivity قرار دادم
وقتی برنامه رو خودم اجرا می کنم مشکلی نداره و درست اجرا میشه ولی در استارت آپ خطای Unfortunately MyFirstApp has stopped میاد
می خوام ببینم مشکل از کدهای زیره یا نه؟manifest:
کد پیاچپی:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.myfirstapp"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk android:minSdkVersion="11" android:targetSdkVersion="21" />
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.INTERNET"/>
<application
android:allowBackup="true"
android:icon="@drawable/ic_instagram"
android:label="@string/app_name"
android:theme="@android:style/Theme.Translucent.NoTitleBar" >
<activity android:name=".MyActivity"
android:screenOrientation="portrait"
android:launchMode="singleTask" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<service android:name=".MyService" android:icon="@drawable/icon" android:label="@string/service_name" >
<intent-filter>
<action android:name="com.example.myfirstapp.MyService" />
</intent-filter>
</service>
<receiver
android:name=".receiver.StartMyServiceAtBootReceiver"
android:label="StartMyServiceAtBootReceiver">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
</intent-filter>
</receiver>
</application>
</manifest>
این هم در کلاس MyActivity قرار دادم
کد پیاچپی:
public class StartMyServiceAtBootReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
if (Intent.ACTION_BOOT_COMPLETED.equals(intent.getAction())) {
Intent serviceIntent = new Intent(context, MyService.class);
context.startService(serviceIntent);
}
}
}