I'm using AdMob in my app. I followed implementation guidelines, and the banner is correctly showing and loading the ads. My MainActivity is responsible of creating references, building the AdRequest and showing the banner, as well as pausing, resuming, and destroying the AdView. Everytime the AdRequest has been loaded, when the Activity's onStop() is called, the following Exception is created:
6706-6706/com.rocca.controlloSpese E/ActivityThread﹕ Activity com.rocca.controlloSpese.MainActivity has leaked ServiceConnection com.google.android.gms.common.b#52b1cc3c that was originally bound here
android.app.ServiceConnectionLeaked: Activity com.rocca.controlloSpese.MainActivity has leaked ServiceConnection com.google.android.gms.common.b#52b1cc3c that was originally bound here
at android.app.LoadedApk$ServiceDispatcher.<init>(LoadedApk.java:970)
at android.app.LoadedApk.getServiceDispatcher(LoadedApk.java:864)
at android.app.ContextImpl.bindServiceCommon(ContextImpl.java:1577)
at android.app.ContextImpl.bindService(ContextImpl.java:1560)
at android.content.ContextWrapper.bindService(ContextWrapper.java:517)
at com.google.android.gms.ads.identifier.a.b(SourceFile:330)
at com.google.android.gms.ads.identifier.a.a(SourceFile:187)
at com.google.android.gms.ads.identifier.a.b(SourceFile:239)
at com.google.android.a.t.f(SourceFile:132)
at com.google.android.a.t.b(SourceFile:182)
at com.google.android.a.q.a(SourceFile:258)
at com.google.android.a.q.a(SourceFile:195)
at com.google.android.gms.ads.internal.m.a(SourceFile:107)
at com.google.android.gms.ads.internal.request.c.a(SourceFile:99)
at com.google.android.gms.ads.internal.util.b.run(SourceFile:17)
at com.google.android.gms.ads.internal.util.d.call(SourceFile:29)
at com.google.android.gms.ads.internal.util.e.call(SourceFile:49)
at java.util.concurrent.FutureTask.run(FutureTask.java:237)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
at java.lang.Thread.run(Thread.java:841)
followed by this info:
6706-6781/com.rocca.controlloSpese I/AdvertisingIdClient﹕ AdvertisingIdClient unbindService failed.
java.lang.IllegalArgumentException: Service not registered: com.google.android.gms.common.b#52b1cc3c
at android.app.LoadedApk.forgetServiceDispatcher(LoadedApk.java:922)
at android.app.ContextImpl.unbindService(ContextImpl.java:1611)
at android.content.ContextWrapper.unbindService(ContextWrapper.java:529)
at com.google.android.gms.ads.identifier.a.c(SourceFile:275)
at com.google.android.gms.ads.identifier.b.c(SourceFile:100)
at com.google.android.gms.ads.identifier.b.run(SourceFile:110)
This doesn't happen if the AdRequest is not built and loaded. I set up my IABHelper in onCreate(), and if the user didn't buy my "remove-ads" sku, ads are shown. This is the code I use to load the ads:
private void showAds() {
int adresult = GooglePlayServicesUtil.isGooglePlayServicesAvailable(MainActivity.this);
if (adresult == ConnectionResult.SUCCESS) {
//if possible, show ads
AdRequest adRequest = new AdRequest.Builder()
.addTestDevice(AdRequest.DEVICE_ID_EMULATOR)
.addTestDevice("C144E9DA02EA7B26F74ED2C231F31D38")
.addTestDevice("93BABD84466B8C1EF529D2FB39D1ACE8")
.addTestDevice("BEAA738068664AE9BBF673E37A782E03")
.addTestDevice("E51508081F77DF84C129EE471DE67141")
.build();
adView.setVisibility(View.VISIBLE);
adView.loadAd(adRequest);
} else {
//if there's a problem, show error and close app
GooglePlayServicesUtil.getErrorDialog(adresult, MainActivity.this, 0, new DialogInterface.OnCancelListener() {
#Override
public void onCancel(DialogInterface dialogInterface) {
finish();
}
}).show();
}
}
adView's pause(), resume() and destroy() are called in the respective activity's methods. Practically, the app's performance isn't affected, but I'd rather avoid memory leaks. How do I avoid that exception?
EDIT: the Manifest.xml
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="com.rocca.controlloSpese" >
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="com.android.vending.BILLING" />
<uses-permission android:name="com.rocca.controlloSpese.BROADCAST_PERMISSION" />
<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:finishOnCloseSystemDialogs="true"
android:label="#string/app_name"
android:launchMode="singleTop" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<meta-data
android:name="com.google.android.gms.version"
android:value="#integer/google_play_services_version" />
<activity
android:name="com.google.android.gms.ads.AdActivity"
android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize" />
</application>
I'm seeing exactly the same behaviour just using the example quick start project from the AdMob website here. I'm seeing this running Lollipop on a Nexus 5.
Therefore this looks like an AdMob bug to me.
Is there anyway to get a reference to the AdMob service and unbind the service manually to see if that stops the error?
Below code solve my problem;
#Override
protected void onDestroy() {
// TODO Auto-generated method stub
mAdView.destroy();
super.onDestroy();
}
#Override
protected void onResume() {
// TODO Auto-generated method stub
super.onResume();
mAdView.resume();
}
#Override
protected void onPause() {
// TODO Auto-generated method stub
super.onPause();
mAdView.pause();
}
Related
None of the many similar questions I have found have helped to solve my issue.
Here are some questions I've looked at:
ServiceConnection.onServiceConnected() never called after binding to started service
onServiceConnected never called after bindService method
ServiceConnection::onServiceConnected not called even though Context::bindService returns true?
OnServiceConnected not getting called
Here is part of my android app code:
//Local service interface
private INetworkQueryService myNetworkQueryService = null;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
init();
Intent intent = new Intent(this, NetworkQueryService.class);
startService (intent);
bindService (new Intent(this, NetworkQueryService.class), myNetworkQueryServiceConnection,
Context.BIND_AUTO_CREATE);
}
//Service connection
private final ServiceConnection myNetworkQueryServiceConnection = new ServiceConnection() {
/** Handle the task of binding the local object to the service */
public void onServiceConnected(ComponentName className, IBinder service) {
myNetworkQueryService = ((NetworkQueryService.LocalBinder) service).getService();
// as soon as it is bound, run a query.
loadNetworksList();
}
/** Handle the task of cleaning up the local binding */
public void onServiceDisconnected(ComponentName className) {
myNetworkQueryService = null;
}
public void loadNetworksList() {
// delegate query request to the service.
try {
myNetworkQueryService.startNetworkQuery(myCallback);
} catch (RemoteException e) {
}
}
};
/**
* This implementation of INetworkQueryServiceCallback is used to receive
* callback notifications from the network query service.
*/
private final INetworkQueryServiceCallback myCallback = new INetworkQueryServiceCallback.Stub() {
#Override
public void onQueryComplete(List<NetworkInfo> networkInfoArray,
int status) throws RemoteException {
displayNetworks(networkInfoArray, status);
}
/** place the message on the looper queue upon query completion. */
};
As you can sy, myNetworkQueryServiceConnection should be called from within the bindService method (located in onCreate()). This (in theory) should also run onServiceConnected (I think), but I put a breakpoint in my code and it never stops inside that method. I did some debugging and bindService returns false, so for some reason it's not successfully binding it.
This is my first time ever having to bind services in Android, so I'm sure I've missed something. I'm hoping someone could point out a mistake.
Let me know if you're missing any information--I'm not sure what all you might need, and I really can't post my entire app code here.
EDIT: I keep reading things about registering the service in the manifest but cannot seem to figure out where or how that would be done? Here's the manifest for this project:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.tek15.cellemrmonitor"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="19"
android:targetSdkVersion="21" />
<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>
</application>
I certainly don't see anything about the service, but I guess I don't know how to add it.
You need to add a <service> element, as a peer of your <activity> element, as a child of <application>:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.tek15.cellemrmonitor"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="19"
android:targetSdkVersion="21" />
<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>
<service android:name="NetworkQueryService" />
</application>
My example element assumes that NetworkQueryService is really com.tek15.cellemrmonitor.NetworkQueryService — otherwise, substitute in the proper fully-qualified class name.
I have an application A that has to bind to a service that is in another package. I have put a custom intent filter in order to make it work. Sadly the application wont bind. The log says that it can't find the service.
Application A is in the package "com.example.app_a"
The service is in another package "com.example.app_talker_service"
So I just can't refer to the service with the xxx.class solution, so my guess was to use an intent filter in the manifest file of the service's package.
Application A, on the other hand, will need to do a bind to the service to make it start (if it hasn't already started) and that later it will communicate with it though the use of broadcast receivers. I did some experimentation and I noticed that the broadcasts work fine, but what is wrond is that for some reason, the application A can't seem to find my service during the binding....
Here is the code for application A which binds in onStart():
#Override
protected void onStart()
{
// TODO Auto-generated method stub
super.onStart();
//Bind to service
getApplicationContext().bindService(new Intent("com.example.talker_service.SERVICE"), mConnection,Context.BIND_AUTO_CREATE);
}
private boolean mIsBound = false;
private ServiceConnection mConnection = new ServiceConnection()
{
#Override
public void onServiceConnected(ComponentName name, IBinder service) {
// TODO Auto-generated method stub
mIsBound = true;
Toast.makeText(getApplicationContext(), "CONNECTED TO SERVICE!", Toast.LENGTH_SHORT).show();
Intent intent = new Intent();
intent.setAction("com.example.talker_service.SERVICE");
intent.putExtra("REQUEST", "REGISTER APP");
intent.putExtra("FILTER", "com.example.app_a");
intent.putExtra("NAME", "Applicazione A");
String[] components = {"NUMBER_SENT","CHANGE_TEXT_COLOR","CHANGE_TEXTVIEW_SIZE"};
intent.putExtra("COMPONENTS", components);
MainActivityA.this.sendBroadcast(intent);
}
#Override
public void onServiceDisconnected(ComponentName name) {
// TODO Auto-generated method stub
mIsBound = false;
}
};
Here instead is the cmanifest for the service which I called Talker_service:
en<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.app_talker_service"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="14"
android:targetSdkVersion="19" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<service
android:name=".Talker_Service"
android:enabled="true"
android:exported="true"
android:permission="android.permission.BIND_ACCESSIBILITY_SERVICE" >
<intent-filter >
<action android:name="com.example.talker_service.SERVICE"/>
<category android:name="android.intent.category.DEFAULT"/>
<data android:mimeType="text/plain" />
</intent-filter>
</service>
<activity
android:name=".ConnectionManagerActivity"
android:label="#string/title_activity_connection_manager" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
I don't undertsand why it doesn't bind.. I put the intent filter, am I missing something? Ah, and the logs says this:
12-03 22:45:13.786: W/ContextImpl(26076): Implicit intents with startService are
not safe: Intent {
act=com.example.talker_service.SERVICE }
android.content.ContextWrapper.bindService:517
com.example.app_a.MainActivityA.onStart:81
android.app.Instrumentation.callActivityOnStart:1171
12-03 22:45:13.786: W/ActivityManager(764): Unable to start service Intent { >act=com.example.talker_service.SERVICE } U=0: not
found
This instead is the manifest file for application A
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.app_a"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="14"
android:targetSdkVersion="19" />
<uses-permission android:name="android.permission.BIND_ACCESSIBILITY_SERVICE" ></uses-permission>
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name=".MainActivityA"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
I don't know why using intent filters is not working (it says that it can't find it) but by using the following code I was able to make my application connect to the remote service:
Intent i = new Intent();
i.setClassName("com.example.app_talker_service", "com.example.app_talker_service.Talker_Service");
bindService(i, conn, Context.BIND_AUTO_CREATE);
so using the seClassName method and providing the name of the pacake and that full path of the service, I was able to make it work. I am not sure if this falls in the realm of "best practice" for this type of problem, but for my it worked. Any solution is better than no solution. I found this solution thants to this link:
Remote Service Tutorial
For the first time im trying to set a landscape orientation on my app. Im having so much problems cause it uses actionbar.tab's and service and i dont know very well yet how all of this will happens on each fragment specifically. The first problem i faced was the asynchrony between activity lifecycle and service, cause the service was unbind when the activity was already recreated. Then i tried to set android:configChanges="orientation" on my manifest to manually handle the events, but the activity stills recreating itself.
I dont know how i will handle so many details on orientation changes, the most of data and information i have to retrieve is on service, it guards my app state, but im not getting do it.
Please help me before i give up implementing this funcion on my app.
I will post some code.
This is the manifest:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.irclient2"
android:versionCode="1"
android:versionName="1.0" >
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<uses-sdk
android:minSdkVersion="10"
android:targetSdkVersion="19" />
<application
android:allowBackup="true"
android:debuggable="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name="com.example.irclient2.activity.MainActivity"
android:configChanges="orientation|keyboardHidden"
android:label="#string/app_name"
android:theme="#style/Theme.AppCompat.Light.DarkActionBar" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<service
android:name="com.example.irclient2.service.MyService"
android:exported="false" >
</service>
<!-- AS DUAS TAGS SEGUINTES SÃO APENAS PARA O FUNCIONAMENTO DO ADMOB -->
<meta-data
android:name="com.google.android.gms.version"
android:value="#integer/google_play_services_version" />
<activity
android:name="com.google.android.gms.ads.AdActivity"
android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize" />
</application>
</manifest>
This is my activity:
public class MainActivity extends ActionBarActivity implements
ServiceConnection {
#Override
protected void onCreate(Bundle savedInstanceState) {
MyService.log("Activity onCreate()");
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_layout);
actionBar = getSupportActionBar();
actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
actionBar.setDisplayShowTitleEnabled(false);
drawerlayout = (DrawerLayout) findViewById(R.id.drawer_layout);
drawerlayout.setDrawerShadow(R.drawable.drawer_shadow, Gravity.LEFT);
registerReceivers();
cancelaNotificacao(R.drawable.ic_launcher);
Intent it = new Intent(this, MyService.class);
if (!MyService.RUNNING) {
startService(it);
}
if (!bindService(it, this, 0)) {
mensagemErro("Erro!",
"Não foi possível conectar ao service. Fechando app.");
finish();
}
}
#Override
protected void onDestroy() {
MyService.log("Activity onDestroy()");
unregisterReceivers();
unbindService(this);
super.onDestroy();
}
#Override
public void onConfigurationChanged(Configuration newConfig) {
// /////////////////////// CASO PORTRAIT ///////////////////////////
if (newConfig.orientation == Configuration.ORIENTATION_LANDSCAPE) {
}
// /////////////////////// CASO LANDSCAPE ///////////////////////////
if (newConfig.orientation == Configuration.ORIENTATION_LANDSCAPE) {
}
}
#Override
public void onServiceConnected(ComponentName name, IBinder binderservice) {
MyService.log("Activity onServiceConnected");
LocalBinder binder = (LocalBinder) binderservice;
this.service = binder.getService();
carregaRadio();
if (MyService.bot != null && MyService.bot.isConnected()) {
carregaChatdoService();
selectTab(TITLE_TAB_CHAT);
} else {
carregaLogin();
selectTab(TITLE_TAB_RADIO);
}
}
#Override
public void onServiceDisconnected(ComponentName name) {
service = null;
}
//////////// THERE ARE MORE THINGS //////////
My RelativeLayout that is the custom view for the actionbar.tabs:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="0dip"
android:layout_height="64dip"
android:layout_marginLeft="-3dip"
android:layout_marginRight="-3dip"
android:layout_weight="1"
android:orientation="vertical" >
<TextView
android:id="#+id/tabtitle"
style="?android:attr/tabWidgetStyle"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_centerHorizontal="true"
android:text="Tab Title" />
</RelativeLayout>
Due to my activity always get the data from service, i though it would be easilly with activity being recreated, but i had problems with service connection during the process because service bind and unbind are called and assynchronous.
As i already said, is my first time doing it, please tell me what is best thing to do.
Thanks in advance.
You can use this line of code , in your activity , before the setContentView(R.layout.yourlayout) ;
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT) ;
and for the android 3.2+ , you should also add this :
android:configChanges="orientation|screenSize"
And study the documentation here!
We are developing an Android app.
We are going to wake up Lock-mode, when our App receives a GCM message in Sleep mode.
program works well in Android 4.1 (Jelly-Bean, API 16).
but it does not work in Android 4.3 (Jelly-Bean, API 19).
What is the problem? Please let us know!!!
We programmed as follows:
follow is class files :
public class GCMIntentService extends GCMBaseIntentService {
#Override
protected void onMessage(Context context, Intent intent) {
//...some code omitted...
Intent newIntent;
newIntent = new Intent(context, SomeActivity.class);
newIntent.setFlags(
Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP);
context.startActivity(newIntent);
}
}
public class SomeActivity extends Activity {
#Override
protected void onCreate(Bundle savedInstanceState) {
//...some code omitted...
WakeLockManager.setWakeUp(this);
//...some code omitted...
super.onCreate(savedInstanceState);
}
#Override
protected void onStart() {
//...some code omitted...
super.onStart();
}
#Override
protected void onResume() {
//...some code omitted...
super.onStart();
}
#Override
protected void onPause() {
//...some code omitted...
super.onPause();
}
protected void onStop() {
//...some code omitted...
super.onStop();
};
#Override
protected void onDestroy() {
//...some code omitted...
super.onDestroy();
}
}
public class WakeLockManager {
public static void setWakeUp(Context context) {
Window wnd = ((Activity)context).getWindow();
wnd.addFlags(
WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD |
WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED |
WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON |
WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON
);
}
}
follow is manifest file :
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.mycompany.myapp"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="16"
android:targetSdkVersion="19" />
<permission
android:name="com.mycompany.myapp.permission.C2D_MESSAGE"
android:protectionLevel="signature" />
<uses-permission android:name="com.mycompany.myapp.permission.C2D_MESSAGE" />
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.DISABLE_KEYGUARD"/>
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<uses-permission android:name="android.permission.CALL_PHONE"/>
<application
android:name="com.mycompany.myapp"
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppBaseTheme" >
<receiver
android:name="com.google.android.gcm.GCMBroadcastReceiver"
android:permission="com.google.android.c2dm.permission.SEND" >
<intent-filter>
<action android:name="com.google.android.c2dm.intent.RECEIVE" />
<action android:name="com.google.android.c2dm.intent.REGISTRATION" />
<category android:name="com.mycompany.myapp" />
</intent-filter>
</receiver>
<service android:name="com.mycompany.myapp.GCMIntentService" />
<activity
android:name="com.mycompany.myapp.activities.SomeActivity"
android:configChanges="orientation"
android:label="#string/app_name"
android:theme="#style/NoActionBar"
android:screenOrientation="landscape" >
</activity>
<activity
android:name="com.appkorea.newdriver.activities.MainActivity"
android:configChanges="orientation"
android:label="#string/app_name"
android:theme="#style/AuthTheme"
android:screenOrientation="landscape" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<!-- ...some code omitted... -->
</application>
</manifest>
in case of API 19, when staring SomeActivity, the onCreate() call-back function is called over 1 times.
I guess several reason as follow.
1. SomeActivity's screenOrientation value is landscape.
So for rotating activity, the onCreate() call-back function is called once.
2. To unlock the lockScreen, the android system show the lock screen,
and rotate the screen into portrait.
because current lock-screen's screenOrientation value is portrait.
At this time, SomeActivity is already created.
so the onCreate call-back function is called once.
3. After unlocking, To show the SomeActivity, the onCreate() is called once.
but now device screenOrientation is portrait,
and SomeActivity's screenOrientation is landscape.
so the onCreate() is called again.
As above that is written, onCreate() is called over 1 times. Unfortunately I don't have a android phone 4.3 now. So I can not show the logcat. Later soon, I will upload the logcat screen capture. Really Thanks to read.
I m trying to start an IntentService from the main activity of y application and it won't start. I have the service in the manifest file. Here's the code:
MainActivity
public class Home extends Activity {
private LinearLayout kontejner;
IntentFilter intentFilter;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_home);
kontejner = (LinearLayout) findViewById(R.id.kontejner);
intentFilter = new IntentFilter();
startService(new Intent(getBaseContext(), HomeService.class));
}
}
Service:
public class HomeService extends IntentService {
public HomeService() {
super("HomeService");
// TODO Auto-generated constructor stub
}
#Override
protected void onHandleIntent(Intent intent) {
Toast.makeText(getBaseContext(), "TEST", Toast.LENGTH_LONG).show();
}
}
Manifest:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.salefinder"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="15" />
<application
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name=".Home"
android:label="#string/title_activity_home" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<service android:name=".HomeService" />
</application>
<uses-permission android:name="android.permission.INTERNET"/>
</manifest>
How can I make it work?
onHandleIntent gets called from a background thread. You can't modify the UI, or in this case, make Toast from outside the UI thread. So, I wouldn't expect anything to happen with your service.
Just try writing something out with Log.d() to see if your service is getting called.
It seams that android cached a bad version of the app - I forced closed it and started it again, and it worked...