About android.intent.action.BOOT_COMPLETED [closed] - android

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 7 years ago.
Improve this question
I write a sample to learn BroadcastReceiver..But When I reboot my phone, the app broke down. Here is my source code and manifest.xml:
public class MainActivity extends Activity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
public class BootCompleteReceiver extends BroadcastReceiver
{
#Override
public void onReceive(Context context, Intent intent) {
Toast.makeText(context,"Boot Complete",Toast.LENGTH_LONG).show();
}
}
}
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.boot"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="14"
android:targetSdkVersion="17" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name=".MainActivity"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<receiver android:name=".BootCompleteReceiver" >
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
</intent-filter>
</receiver>
</application>
</manifest>

You do not have a class named com.example.boot.BootCompleteReceiver, at least based on the code that you have shown in your answer.
While you have a class named BootCompleteReceiver:
It is an inner class of MainActivity, and so BootCompleteReceiver is not named com.example.boot.BootCompleteReceiver
It is a regular inner class of MainActivity (no static keyword), and so Android could not create an instance of it anyway, even if you had the right name in the manifest
Either move BootCompleteReceiver to be a regular standalone Java class in its own .java file, or make it be a public static class inside MainActivity. In the latter case, the fully-qualified class name for your manifest entry would be com.example.boot.MainActivity$BootCompleteReceiver.

Related

Extended Application can not run correctly

everyone. I am new to android.
Recently, I tried to learn how to extend Application, but there is
a strange problem. I have tried a lot of methods, but still can not
solve it. So, thanks in advance if anyone can help me.
The code section is like this:
package com.example.xw.myfirstapplication;
import android.app.Application;
/**
* Created by Administrator on 2016/8/26.
*/
public class MyApplication extends Application {
public static MyApplication mApplication;
#Override
public void onCreate(){
super.onCreate();
mApplication = this;
}
public static MyApplication getMyApplication(){
return mApplication;
}
}
And, Manifest.xml is like this:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.xw.myfirstapplication"
>
<uses-sdk
android:minSdkVersion="19"
android:targetSdkVersion="24" />
<uses-permission android:name="android.permission.INTERNET"/>
<application android:name="com.example.xw.myfirstapplication.MyApplication"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
>
<!--<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>-->
<!--<uses-permission android:name="android.permission.INTERNET"></uses-permission>-->
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<!--<activity android:name="testNewTech.DisplayMessageActivity" />
<activity android:name="testNewTech.NotificationActivity"></activity>-->
</application>
</manifest>
But, when I run the code, something happens very quickly, like this:
In addition:
1. I tried not to use extended Application but default Application, everything is good.
I add Log.v("MainActivity", "start onCreate"); in method onCreate() of class MainActivity. But, there is nothing in logcat, so I think the method onCreate() of class MainActivity is not processed.
So, anyone has any advice? Thank you so much!
If you can see in your manifest.xml file then you can pass another class
<application android:name="com.example.xw.myfirstapplication.MyApplication"
...
...
>
just change
<application android:name="com.example.xw.myfirstapplication.Application"
...
...
>

How does an android program understands which class or/and activity to call first?

As i am new to android programming, I don't know how to call a certain class and/or certain activity first.
For example i have two classes viz. 1) Login.java 2) Create.java and two xml files associated with them are activity_main.xml and create_new.xml respectively.
So how can i make Login.java run first with activity_main.xml as screen?
in login java use this
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);}
in create java us this
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.create_new);
in androidmanifest
<activity
android:name=".Login"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
and another activities
<activity android:name=".MainActivity" ></activity>
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.your.package"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="10"
android:targetSdkVersion="19" />
<uses-permission android:name="android.permission.INTERNET" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name="com.example.your.package.activity.Login"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name="com.example.your.package.activity.Create"
android:label="#string/app_name" >
</activity>
</application>
</manifest>
In this case, the intent-filter of LOGIN activity specifies that the intent with action of MAIN and category of LAUNCHER will be caught by it, aka it is where the application starts.
Afterwards,
public class Login extends Activity
{
//honestly I'd name this class LoginActivity and same in the XML
#Override
public void onCreate(Bundle saveInstanceState)
{
super.onCreate(saveInstanceState);
setContentView(R.layout.activity_main);
}
....
}
Also look at this example to learn how to use Fragments:
NullPointerException accessing views in onCreate()
from the intent filters you decalre in the android manifest file of your project;see the image
You declare an intent filter in the activity tag something like shown in the image for making it the first activity of your application.and if there are other activities in your app having intent filters than you have to just change the capital letter MAIN to DEFAULT in the intent filter tag
You will find AndroidManifest file like in the following image in your project

Android parse.com Can't receive push notification

I can't receive push notifications, using parse.com service.
I used a quick guide trying to solve my problem. I was trying to use channel this specified name and "" as a channel name. Also i found Cannot receive push notifications in Android with trigger.io and parse.com
I succeed to send object to parse.com, and to subscribe for notifications (at least I can see my app in DataBrowser on parse.com)
public class ParseStarterProjectActivity extends Activity {
/** Called when the activity is first created. */
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
PushService.subscribe(this, "push", TestParse.class);
PushService.setDefaultPushCallback(this, TestParse.class);
}
}
public class ParseApplication extends Application {
#Override
public void onCreate() {
super.onCreate();
Parse.initialize(this, my_id, my_client_key);
}
}
public class TestParse extends Activity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.parse);
}
}
AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.parse.starter"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="4"
android:targetSdkVersion="17" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<uses-permission android:name="android.permission.VIBRATE" />
<application
android:name="ParseApplication"
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name" >
<service android:name="com.parse.PushService" />
<receiver android:name="com.parse.ParseBroadcastReceiver" >
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
<action android:name="android.intent.action.USER_PRESENT" />
</intent-filter>
</receiver>
<activity
android:name=".ParseStarterProjectActivity"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".TestParse"
android:label="#string/app_name" />
</application>
</manifest>
Recently I've noticed LogCat errors:
02-21 18:17:45.381: ERROR/Trace(8952): error opening trace file: No such file or directory (2)
02-21 18:17:48.534: ERROR/com.parse.PushService(8888): unknown host
I really want to receive notifications. What am I doing wrong?
Parse employee here. In order to handle increased load on our push service, we increased the number of machines serving push.parse.com. Some ISPs started having issues when DNS resolution returned this many servers. Last Friday afternoon, we launched a custom DNS server which works around these issues with 3rd party DNS resolution. This should no longer be an issue.

Android Google Map API:Force Close Error

I have received forced closed error message on running the sample code of Google API.Is update a project is a solution to this type of project? If so then how to update project on window.The method given here don't work on my case.
Here is code
Filename:HelloGoogleMaps.java
package com.hellogooglemaps.practices;
import com.google.android.maps.MapActivity;
import com.google.android.maps.MapView;
import android.os.Bundle;
public class HelloGoogleMaps extends MapActivity {
/** Called when the activity is first created. */
#Override
protected boolean isRouteDisplayed(){
return false;
}
#Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
MapView mapView = (MapView)findViewById(R.id.mapview);
mapView.setBuiltInZoomControls(true);
}
#Override
protected boolean isLocationDisplayed(){
return true;
}
}
HelloGoogleMaps Manifest
<uses-sdk android:minSdkVersion="8" />
<uses-permission android:name="android.permission.INTERNET"/>
<application
android:icon="#drawable/ic_launcher"
android:label="#string/app_name" >
<activity
android:label="#string/app_name"
android:name=".HelloGoogleMapsActivity" >
<intent-filter >
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".HelloGoogleMaps" android:label="#string/app_name"
android:theme="#android:style/Theme.NoTitleBar" />
<uses-library android:name="com.google.android.maps"/>
</application>
main.xml
<?xml version="1.0" encoding="utf-8"?>
<com.google.android.maps.MapView
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/mapview"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:clickable="true"
android:apiKey="0_hYeORLgQUROOOr_RXN2TWG2u2pCDoBYfLCV_w"
/>
As you had mentioned in your code, You have only one Activity called HelloGoogleMaps and in your AndroidManifest you have declared two activities!! your HelloGoogleMapsActivity is useless. You are getting the error because you set HelloGoogleMapsActivity as the Launcher activity and this activity don't even exist!!
Solution:
change your AndroidManifest.xml like that and you will get your app work if you had managed to get the apikey for your map correctly:
<uses-sdk android:minSdkVersion="8" />
<uses-permission android:name="android.permission.INTERNET"/>
<application
android:icon="#drawable/ic_launcher"
android:label="#string/app_name" >
<activity
android:label="#string/app_name"
android:theme="#android:style/Theme.NoTitleBar"
android:name=".HelloGoogleMaps" >
<intent-filter >
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<uses-library android:name="com.google.android.maps"/>
</application>
After facing Force close Error many time what I have found is that these type of error is so common and come due to the undefined behavioral.Like when we declare Button and without assigning the view on it we use it on another function. It is also appear due to not handling the exception correctly. or Due to unavailable of resource your are trying to access in emulator like contact number. Best method to solve these type of problem is using log and printing some message on place where we feel confusing and using logcat.
In above case I had received force close error due to undefined behavior in HelloGoogleMapsActivity class

Is it mandatory to have broadcast receiver as a separate file?

I have declared an activity and a broadcast receiver in my manifest file, however, I have the code for onReceive() in my activity as a separate public class. When I try to trigger a broadcast from the adb command line I get a classnotfound error.
My question is, is it mandatory to have the broadcastreceiver as a separate class in a separate file ?
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
ActivityAsDialogActivity.this.requestWindowFeature(Window.FEATURE_NO_TITLE);
:
:
}
public class TestEmail extends BroadcastReceiver{
#Override
public void onReceive(Context context, Intent intent) {
if (intent.getAction().equals(MYINTENT)){
Log.d("Manju ==>","ActivityAsDialogActivity, Got the intent"+MYINTENT);
Toast.makeText(context, "Don't panik but your time is up!!!!.",
Toast.LENGTH_LONG).show();
}//end of if statment
}//end of onReceiver
}//end of Broadcast
}//end of class ActivityAsDialogActivity
below is manifest file
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.mot.activityasdialog"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk android:minSdkVersion="15" />
<application
android:icon="#drawable/ic_launcher"
android:label="#string/app_name" >
<activity
android:name=".ActivityAsDialogActivity"
android:excludeFromRecents="true"
android:theme="#style/EmptyActivity"
android:configChanges="keyboardHidden|orientation|screenSize|uiMode">
<!-- android:theme="#android:style/Theme.Holo.Dialog"
android:label="#string/app_name" -->
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<receiver android:name="com.mot.activityasdialog.ActivityAsDialogActivity.TestEmail" android:enabled="true">
<intent-filter>
<action android:name="com.mot.MANJU"></action>
</intent-filter>
</receiver>
</application>
</manifest>
Short answer: Yes it needs to be a different Class. And in a separate file.
Long answer: Since your BroadcastReceiver must be a subclass of BroadcastReceiver and your Activity must be a subclass of Activity and Java does not allow multiple inheritance and Activity and BroadcastReceiver are not related in a suitable fashion. Yes, it has to be two classes.
It seems to have to be in its own file too. I tried it and the system cannot find the BroadcastReceiver if it is an inner class. public or not.

Categories

Resources