[Q] How to link to Settings>Account>Location? - Java for Android App Development

I can link to System settings>Location access with Settings.ACTION_LOCATION_SOURCE_SETTINGS
Fine...but I want to link to System settings>Accounts(Google)>Location settings (this screen is called Google apps location settings)
Does someone know how to do this? Or at least how to get close to there?
Another issue I'm struggling with is how to link to PlayStore>Settings>Ads screen. Has someone an idea?

In the App Ops screen on Android 4.3, find the activity in the settings that you like to open, and launch it the usual way via intent. If you don't have 4.3 yet, you'd have to look at the Android source code and find it there

SimplicityApks said:
In the App Ops screen on Android 4.3, find the activity in the settings that you like to open, and launch it the usual way via intent. If you don't have 4.3 yet, you'd have to look at the Android source code and find it there
Click to expand...
Click to collapse
Thank you for your reply. I can try 4.3 soon. I planned to be compatible with 4.1+. If it is only possible to support 4.3+, that is at least something. Can you tell me how I can code it under 4.3+?`

I would list all activities on my device using the solution provided here.
Then choose the right one from the settings app.

alterechtschreibung said:
Thank you for your reply. I can try 4.3 soon. I planned to be compatible with 4.1+. If it is only possible to support 4.3+, that is at least something. Can you tell me how I can code it under 4.3+?`
Click to expand...
Click to collapse
OK sry, my fault. You don't need 4.3, just create a shortcut in Nova Launcher with activities - >settings and search the right activity. Why I thought 4.3 was needed is only because that was where I created a shortcut on the Homescreen to an activity the last time...
The code itself is clear:
Code:
Intent I = new Intent( "com.google.android.location.settings.GoogleLocationSettingsActivity" );
startActivity(i);
Edit got it!
You probably mean this screen:
"com.google.android.location.settings.GoogleLocationSettingsActivity"

SimplicityApks said:
OK sry, my fault. You don't need 4.3, just create a shortcut in Nova Launcher with activities - >settings and search the right activity. Why I thought 4.3 was needed is only because that was where I created a shortcut on the Homescreen to an activity the last time...
The code itself is clear:
Code:
Intent I = new Intent( "com.google.android.location.settings.GoogleLocationSettingsActivity" );
startActivity(i);
Edit got it!
You probably mean this screen:
"com.google.android.location.settings.GoogleLocationSettingsActivity"
Click to expand...
Click to collapse
Thank you. Unfortunately app crashes when calling it:
I/ActivityManager( 1473): START {act=com.google.android.location.settings.GoogleLocationSettingsActivity u=0} from pid 3501
D/AndroidRuntime( 3501): Shutting down VM
W/dalvikvm( 3501): threadid=1: thread exiting with uncaught exception (group=0x40a9f300)
E/AndroidRuntime( 3501): FATAL EXCEPTION: main
E/AndroidRuntime( 3501): java.lang.IllegalStateException: Could not execute method of the activity

alterechtschreibung said:
Thank you. Unfortunately app crashes when calling it:
I/ActivityManager( 1473): START {act=com.google.android.location.settings.GoogleLocationSettingsActivity u=0} from pid 3501
D/AndroidRuntime( 3501): Shutting down VM
W/dalvikvm( 3501): threadid=1: thread exiting with uncaught exception (group=0x40a9f300)
E/AndroidRuntime( 3501): FATAL EXCEPTION: main
E/AndroidRuntime( 3501): java.lang.IllegalStateException: Could not execute method of the activity
Click to expand...
Click to collapse
I also modified the code with no luck:
public void showClick_google_apps_location_settings(View view) {
Intent intent = showGoogleAppsLocationSettings();
startActivity(intent);
}
public static Intent showGoogleAppsLocationSettings() {
Intent intent = new Intent("com.google.android.location.settings.GoogleLocationSettingsActivity");
intent.addFlags(Intent.FLAG_ACTIVITY_NO_HISTORY | Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET);
return intent;
}

Strange... Normally this should work... Maybe try to set the method not static but that shouldn't do anything actually.

SimplicityApks said:
Strange... Normally this should work... Maybe try to set the method not static but that shouldn't do anything actually.
Click to expand...
Click to collapse
Do I need certain permissions for com.google.android.location.settings.GoogleLocationSettingsActivity?

Usually not... You're testing on a real device, not an emulator aren't you?

SimplicityApks said:
Usually not... You're testing on a real device, not an emulator aren't you?
Click to expand...
Click to collapse
I'm on a real device with Android 4.1.x
I tried Nova Launcher. There is this entry:
settings.GoogleLocationSettings$Activity
Google apps location settings
This shortcut in Nova works. In my app it causes the crash.
If there is further code required, just tell me.

I hope probably not.That's it....
Sent from my Xperia U using xda app-developers app

Karchikumar said:
I hope probably not.That's it....
Sent from my Xperia U using xda app-developers app
Click to expand...
Click to collapse
What's wrong with testing on a real device? Finally the app must run on real devices and not in an emulator.

alterechtschreibung said:
What's wrong with testing on a real device? Finally the app must run on real devices and not in an emulator.
Click to expand...
Click to collapse
Nothing, testing on the emulator could crash since the Goggle settings may not be installed.
Really interesting and strange that it crashes, the only thing you can do now is to try other shortcuts and see if they work and it is just the Google location setting.

SimplicityApks said:
Nothing, testing on the emulator could crash since the Goggle settings may not be installed.
Really interesting and strange that it crashes, the only thing you can do now is to try other shortcuts and see if they work and it is just the Google location setting.
Click to expand...
Click to collapse
That works:
public void showClick_backup_restore_settings(View view) {
Intent intent = showBackupRestoreSettings();
startActivity(intent);
}
public static Intent showBackupRestoreSettings() {
Intent intent = new Intent(Settings.ACTION_PRIVACY_SETTINGS);
intent.addFlags(Intent.FLAG_ACTIVITY_NO_HISTORY | Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET);
return intent;
}
and that works too:
public void showClick_google_apps_location_settings(View view) {
PackageManager packageManager = getPackageManager();
String packageName = ("com.dozingcatsoftware.asciicam");
try {
Intent intent = packageManager.getLaunchIntentForPackage(packageName);
if(null != intent) {
startActivity(intent);
}
}
catch (ActivityNotFoundException e) {
e.printStackTrace();
}
}
-----
while this doesn't work:
public void showClick_google_apps_location_settings(View view) {
PackageManager packageManager = getPackageManager();
String packageName = ("com.google.android.location.settings.GoogleLocationSettingsActivity");
try {
Intent intent = packageManager.getLaunchIntentForPackage(packageName);
if(null != intent) {
startActivity(intent);
}
}
catch (ActivityNotFoundException e) {
e.printStackTrace();
}
}
and this doesn't work either:
public void showClick_google_apps_location_settings(View view) {
Intent intent = showGoogleAppsLocationSettings();
startActivity(intent);
}
public static Intent showGoogleAppsLocationSettings() {
Intent intent = new Intent("com.google.android.location.settings.GoogleLocationSettingsActivity");
intent.addFlags(Intent.FLAG_ACTIVITY_NO_HISTORY | Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET);
return intent;
}

Related

[Q] timer keeps going after app has been terminated?

I am making an app that plays sounds in a loop based on a timer. after I exit the program using finish(); the sounds keep playing in background anyway. Any ideas of why this is and how I can fix it (besides having to use a task killer every time)
thanks
hyperbyteX said:
I am making an app that plays sounds in a loop based on a timer. after I exit the program using finish(); the sounds keep playing in background anyway. Any ideas of why this is and how I can fix it (besides having to use a task killer every time)
thanks
Click to expand...
Click to collapse
finish() just closes the activity, it does *NOT* close the app. Threads will continue to run, services will continue to run, broadcast receivers will continue to receive, etc...
You need to actually stop/cancel the timer if you want it to stop.
I recommend reading this (and then re-reading it again): http://developer.android.com/guide/topics/fundamentals.html and this http://developer.android.com/guide/topics/fundamentals/processes-and-threads.html
hyperbyteX said:
I am making an app that plays sounds in a loop based on a timer. after I exit the program using finish(); the sounds keep playing in background anyway. Any ideas of why this is and how I can fix it (besides having to use a task killer every time)
thanks
Click to expand...
Click to collapse
The timer probably uses the system timer service, Which calls your sound file again and again.
Stop the timer in the onDestory function of your activity.
how exactly do I stop it?
hyperbyteX said:
how exactly do I stop it?
Click to expand...
Click to collapse
Take a look at the documentation from google. probably something like .stop(timer)
don't know
heres the code Im using:
// set timer
TimerTask scanTask = null;
final Handler handler = new Handler();
Timer t = new Timer();
scanTask = new TimerTask() {
public void run() {
handler.post(new Runnable() {
public void run() {
// stuff to run goes here
}
}
});
}};
t.schedule(scanTask, 1, 50); // time how often stuff happens
I've tried many ways to kill it but nothing seems to work
hyperbyteX said:
heres the code Im using:
// set timer
TimerTask scanTask = null;
final Handler handler = new Handler();
Timer t = new Timer();
scanTask = new TimerTask() {
public void run() {
handler.post(new Runnable() {
public void run() {
// stuff to run goes here
}
}
});
}};
t.schedule(scanTask, 1, 50); // time how often stuff happens
I've tried many ways to kill it but nothing seems to work
Click to expand...
Click to collapse
Did you try TimerTask .cancel(); ?
Dark3n said:
Did you try TimerTask .cancel(); ?
Click to expand...
Click to collapse
yeah I tried that but it gives me an error saying "Cannot make a static reference to the non-static method cancel() from the type TimerTask"
Ok, thank you very much. I had to tweak it a bit but I got it!

LinearLayout Hyperlink

Hello!
First at all, I'm a beginner in android coding, I'm more a graphist with Photoshop as main tool.
A friend has made an app for my themes and is in holidays until september.
Beeing logical and understanding fast, with my friend Google we found the functions/codes I needed. Except one:
I have a horizontal scroll layout showing the apps needed to install the theme. Each app is showed in a linearlayout.
What I would like is make each linearlayout of apps clickable and make them show the app on the playstore when you click on it.
Thanks for reading
I assume you're using Textviews to add line by line the dependencies.. There is a property called autolink or very much like it that makes a link whenever it finds a url in the text...
But instead of Textviews in a linearlayout, why not use ListView? Then you can handle the click in the item to create an intent to open the browser with the url needed... it's a bit of more work but has a better esthetic than a bunch of TextViews... For instance, it makes it easier to use when in a ldpi device...
Sent from my LG-P350 using xda app-developers app
Sorry for the late.
I'm beginner in java coding so I don't undersand well what you mean dude.
In fact, what I have now is:
In res\layout\main.xml:
Code:
<HorizontalScrollView
android:id="@+id/layout5"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="@id/layout3"
android:layout_marginLeft="8dp"
android:layout_marginRight="8dp"
android:layout_marginTop="8dp"
>
<LinearLayout
android:id="@+id/layout4"
android:background="#00000000"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal" >
</LinearLayout>
</HorizontalScrollView>
In MainActivity.java:
Code:
boolean apexInstalled = appInstalledOrNot("com.anddoes.launcher");
RelativeLayout apexApp = (RelativeLayout) getLayoutInflater().inflate(R.layout.item, null);
RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams((int) (125 * scale + 0.5f),(int) (150 * scale + 0.5f));
ImageView apexI = (ImageView) apexApp.findViewById(R.id.appIcon);
apexI.setBackgroundResource(R.drawable.apexicon);
TextView apexT = (TextView) apexApp.findViewById(R.id.appText);
if(apexInstalled){
apexT.setText(R.string.installe);
apexT.setTextColor(Color.parseColor("#5a925d"));
}
else{
apexT.setText(R.string.nninstalle);
apexT.setTextColor(Color.parseColor("#de3747"));
}
apexT.setTypeface(font);
TextView apexTitle = (TextView) apexApp.findViewById(R.id.appTitle);
apexTitle.setText("Apex Launcher"); // \n == retour a la ligne
apexTitle.setTypeface(font);
apexApp.setBackgroundColor(Color.argb(190, 0, 0, 0));
listApp.addView(apexApp, params);
And I have many blocks like this one but with other apps, and I would like them to point on the playstore, what do I have to add?
Use a ListView with a custom Adapter: http://www.vogella.com/articles/AndroidListView/
Then add an OnItemClickedListener to the ListView.
In its onItemClick method you can use an Intent like this one:
Code:
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("market://details?id=" + pkg); //Your package name here
if (getActivity().getPackageManager().queryIntentActivities(intent, 0).size() > 0) {
startActivity(intent);
} else {
Toast.makeText(getActivity(), "Google Play is not installed on the device.", Toast.LENGTH_LONG).show();
}
Thanks trying to help me, but I understand aproximatively the intent, but the listview etc, no..
I'm just trying to modify a bit an app somebody made for me using my logic to understand what I have to do. The problem is that I don't understand how to apply what you tell me :/
Lyechee said:
Thanks trying to help me, but I understand aproximatively the intent, but the listview etc, no..
I'm just trying to modify a bit an app somebody made for me using my logic to understand what I have to do. The problem is that I don't understand how to apply what you tell me :/
Click to expand...
Click to collapse
OK, then let's forget about the ListView if you just want to modify your existing app with as little effort as possible.
Try that in your Java code:
Code:
LinearLayout layout = findViewById(R.id.layout4);
layout.setClickable(true);
layout.setOnClickListener(new View.OnClickListener() {
[user=439709]@override[/user]
public void onClick(View v) {
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("market://details?id=" + pkg); //Your package name here
if (getActivity().getPackageManager().queryIntentActivities(intent, 0).size() > 0) {
startActivity(intent);
} else {
Toast.makeText(getActivity(), "Google Play is not installed on the device.", Toast.LENGTH_LONG).show();
}
}
});
(The word Override has to be written with a capital letter at the beginning. XDA does not allow that.)
But if I understand well that code, it will make a "link case" in the whole scroll layout no?
Or a link for each app?
If it's not possible to cut the horizontal scroll in little squares (links), is that possible to put a hyperlink on each imageview? So that click on the icon shows the store.
Lyechee said:
But if I understand well that code, it will make a "link case" in the whole scroll layout no?
Or a link for each app?
If it's not possible to cut the horizontal scroll in little squares (links), is that possible to put a hyperlink on each imageview? So that click on the icon shows the store.
Click to expand...
Click to collapse
Yes, it does. I thought that the Linear layout was loaded as the layout for each app.
Ok. I think that the RelativeLayout in the MainActivity.java is your row, right?
If it is, that should work:
Code:
apexApp.setClickable(true);
apexApp.setOnClickListener(new View.OnClickListener() {
[user=439709]@override[/user]
public void onClick(View v) {
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("market://details?id=" + pkg); //Your package name here
if (getActivity().getPackageManager().queryIntentActivities(intent, 0).size() > 0) {
startActivity(intent);
} else {
Toast.makeText(getActivity(), "Google Play is not installed on the device.", Toast.LENGTH_LONG).show();
}
}
});
Yeah, each RelativeLayout is an app square. I'm not at home so I can't test it now, will later in the evening, thanks for your help!
Lyechee said:
Yeah, each RelativeLayout is an app square. I'm not at home so I can't test it now, will later in the evening, thanks for your help!
Click to expand...
Click to collapse
Welcome.
Hello! I'm in front of a problem.
I wanted to face it alone, but I don't manage it..
I have had a problem with "uri", and after googleing, I've found that I had to import it.
But my problem is that I get that error:
Code:
The method getActivity() is undefined for the type new View.OnClickListener(){}
Any idea?
Lyechee said:
Hello! I'm in front of a problem.
I wanted to face it alone, but I don't manage it..
I have had a problem with "uri", and after googleing, I've found that I had to import it.
But my problem is that I get that error:
Code:
The method getActivity() is undefined for the type new View.OnClickListener(){}
Any idea?
Click to expand...
Click to collapse
Ah, you're right. I'm sorry.
I copied the code from one of my fragments. Just delete the getActivity().
So it is:
Code:
apexApp.setClickable(true);
apexApp.setOnClickListener(new View.OnClickListener() {
[user=439709]@override[/user]
public void onClick(View v) {
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("market://details?id=" + pkg); //Your package name here
if (getPackageManager().queryIntentActivities(intent, 0).size() > 0) {
startActivity(intent);
} else {
Toast.makeText(MainActivtiy.this, "Google Play is not installed on the device.", Toast.LENGTH_LONG).show(); //replace the MainActivity by your Activity
}
}
});
Works like a charm, thank you a lot Exactly what I wanted
If you need a graphist, I'm your man
PS: Is there a tool in Eclipse to make blocks of code lines? I mean, put them in blocs and then hide what you don't need.
Lyechee said:
Works like a charm, thank you a lot Exactly what I wanted
If you need a graphist, I'm your man
PS: Is there a tool in Eclipse to make blocks of code lines? I mean, put them in blocs and then hide what you don't need.
Click to expand...
Click to collapse
Yeah, there should be a minus on the left side next to each method. Click on it to hide the method.
Want to be added? [INDEX] List of themers and designers

How can I count how many fragments are there in an activity?

Hi guys,
I just want to know if there is some code to get the current number of fragments displayed on the screen.
Reason for this is, I can tell if two different of them overlaps, but I can't tell if they're equal.
I tried getSupportFragmentManager().getFragments().size() but it doesn't work as it seems as getSupportFragmentManager().getFragments() returns null...
domenicop said:
Hi guys,
I just wanting to know if there is some code to get the current number of fragments displayed on the screen.
Reason for this is, I can tell if two different of them overlaps, but I can't tell if they're equal.
I tried getSuppoertFragmentManager().getFragments().size() but it doesn't work as it seems, getSuppoertFragmentManager().getFragments() returns null...
Click to expand...
Click to collapse
No one can do that? It would be such a helpful little snippet of code....
Maybe you called the method before the Fragments were created? Or you're using a ViewPager. Code...
nikwen said:
Maybe you called the method before the Fragments were created? Or you're using a ViewPager. Code...
Click to expand...
Click to collapse
I am not asking in regard to a particular snippet of code, the problem is generic. I want to be able to count the fragments that are currently on the screen.
Maybe I understood your answer. You're saying that
Code:
getSupportFragmentManager().getFragments().size()
is the right way to check and so want to see code to check his strange behavior? BTW, I'm using a ViewPager (it is one of the fragments in my activity)
domenicop said:
I am not asking in regard to a particular snippet of code, the problem is generic. I want to be able to count the fragments that are currently on the screen.
Maybe I understood your answer. You're saying that
Code:
getSupportFragmentManager().getFragments().size()
is the right way to check and so want to see code to check his strange behavior? BTW, I'm using a ViewPager (it is one of the fragments in my activity)
Click to expand...
Click to collapse
Do you mean Fragments that are actually visible to the user or just those that have been created?
Yeah, that should be the right code... However, it doesn't include the Fragments which were added to the ViewPager as they haven't been added to the Activity/FragmentManager.
nikwen said:
Do you mean Fragments that are actually visible to the user or just those that have been created?
Yeah, that should be the right code... However, it doesn't include the Fragments which were added to the ViewPager as they haven't been added to the Activity/FragmentManager.
Click to expand...
Click to collapse
This is the main activity (it's the same one as the other post)
Code:
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
// Initialize the mDatabase
mContactsDatabase = ContactsDatabase.getInstance(getApplicationContext());
// Determine device orientation
mDualPane = getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE;
// Set the fragment that will be changed
mFragmentToReplace = mDualPane ? R.id.contactsPagerFragmentContainer : R.id.portraitFragmentContainer;
// Set up the GUI
FragmentManager fm = getSupportFragmentManager();
if (!mDualPane) {
Log.d(TAG, "Orientation Portrait detected.");
// First, look for previously saved fragments
// findByFragmentId(int id) look for the fragment that was previously associated
// to the resource that has for id the argument passed in. Then, we try to cast it
// to the type of fragment we want, and if that's correct, we have our fragment
mContactListFragment = (ContactListFragment) fm.findFragmentById(R.id.portraitFragmentContainer);
if (mContactListFragment == null) {
mContactListFragment = ContactListFragment.newInstance(mContactsDatabase);
fm.beginTransaction()
.replace(R.id.portraitFragmentContainer, mContactListFragment, CONTACT_LIST_FRAGMENT)
.commit();
}
}
else {
Log.d(TAG, "Orientation Landscape detected.");
// First, look for previously saved fragments
mContactListFragment = (ContactListFragment) fm.findFragmentById(R.id.landscapeFragmentContainer);
mContactsPagerFragment = (ContactsPagerFragment) fm.findFragmentById(R.id.contactsPagerFragmentContainer);
if (mContactListFragment == null) {
mContactListFragment = ContactListFragment.newInstance(mContactsDatabase);
fm.beginTransaction()
.replace(R.id.contactListFragmentContainer, mContactListFragment, CONTACT_LIST_FRAGMENT)
.commit();
}
if (mContactsPagerFragment == null) {
final int FIRST_CONTACT_POSITION = 0;
mContactListFragment = ContactListFragment.newInstance(mContactsDatabase);
mContactsPagerFragment =
ContactsPagerFragment.newInstance(FIRST_CONTACT_POSITION, mContactsDatabase);
fm.beginTransaction()
.replace(R.id.contactsPagerFragmentContainer, mContactsPagerFragment, CONTACTS_PAGER_FRAGMENT)
.commit();
}
}
Log.d(TAG, "# of Fragments on the screen" + getSupportFragmentManager().getFragments().size());
}
Penultimate line is the one that throws a NullPointerException.
Working fine for me here:
Code:
# of Fragments on the screen1
nikwen said:
Working fine for me here:
Code:
# of Fragments on the screen1
Click to expand...
Click to collapse
Maybe it's something with the fragments initialization. How did you run your code?
domenicop said:
Penultimate line is the one that throws a NullPointerException.
Click to expand...
Click to collapse
Did you import the right Fragment from the v4 compatibility lib? Otherwise, you'd have to use getFragmentManager() instead!
Edit: I see, you're using it above as well so it shouldn't be the case, could you try to call fm.getFragments() and see what it returns, where fm is the FragmentManager you already created?
@SimplicityApks It was so before, it still crashes if I use the fm fragment manager.
I add the logcat output for what it's worth:
Code:
11-04 23:20:48.640: ERROR/AndroidRuntime(10131): FATAL EXCEPTION: main
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.domenicop.census/com.domenicop.census.MainActivity}: java.lang.NullPointerException
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2339)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2389)
at android.app.ActivityThread.access$600(ActivityThread.java:153)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1269)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:5289)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:525)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:739)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:555)
at de.robv.android.xposed.XposedBridge.main(XposedBridge.java:115)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.NullPointerException
at com.domenicop.census.MainActivity.onCreate(MainActivity.java:104)
at android.app.Activity.performCreate(Activity.java:5133)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2293)
... 12 more
11-04 23:20:48.650: WARN/ActivityManager(2322): Force finishing activity com.domenicop.census/.MainActivity
11-04 23:20:49.185: WARN/ActivityManager(2322): Activity pause timeout for ActivityRecord{42ad16f0 u0 com.domenicop.census/.MainActivity}
MainActivity.java:104 is the penultimate line of the class. The incriminated one.
domenicop said:
MainActivity.java:104 is the penultimate line of the class. The incriminated one.
Click to expand...
Click to collapse
What's null, fm or mContactsPagerFragment ?
fm.getFragments() does return null... How could that possibly be? I just instantiated them. Maybe I have to wait till they construct heir views?
I jus checked in the Android Developer API and I couldn't find any mention about this method. Eclipse was suggesting it.
I guess it's been deprecated, but even if that is true, why would it completely disappear?
Please someone that doublecheck on this. (I found getFragment (Bundle bundle, String key), no trace of getFragment...)
fm.getFragments() does return null... How could that possibly be? I just instantiated the fragments. Maybe I have to wait till they construct heir views?
EDIT
I just checked in the Android Developer API and I couldn't find any mention about this method. Eclipse is suggesting it.
I guess it's been deprecated, but even if that is true, why would it completely disappear?
Please someone that double-check on this. (I found getFragment (Bundle bundle, String key), no trace of getFragment...)
Also, thank you for talking to me, on other forums I feel like an alien when opening a 3d about android developer questions
domenicop said:
fm.getFragments() does return null... How could that possibly be? I just instantiated the fragments. Maybe I have to wait till they construct heir views?
EDIT
I just checked in the Android Developer API and I couldn't find any mention about this method. Eclipse is suggesting it.
I guess it's been deprecated, but even if that is true, why would it completely disappear?
Please someone that double-check on this. (I found getFragment (Bundle bundle, String key), no trace of getFragment...)
Also, thank you for talking to me, on other forums I feel like an alien when opening a 3d about android developer questions
Click to expand...
Click to collapse
Have you tested whether getFragments() returns null even if you call that method later (for example when a button is pressed)?
nikwen said:
Have you tested whether getFragments() returns null even if you call that method later (for example when a button is pressed)?
Click to expand...
Click to collapse
I just checked and it works if I don't call it from the MainActivity, anyway I've to say the results are not that comfortable. In some cases I've seen some output as scary as # of fragments on the screen is 45
It would be nice to know how this method works though. Without documentation, I can't really make any conclusion here.
Thank you for your help, and please report in this thread if you can find any explanation about the behavior of this method.
Bye.
domenicop said:
Hi guys,
I just want to know if there is some code to get the current number of fragments displayed on the screen.
Reason for this is, I can tell if two different of them overlaps, but I can't tell if they're equal.
I tried getSupportFragmentManager().getFragments().size() but it doesn't work as it seems as getSupportFragmentManager().getFragments() returns null...
Click to expand...
Click to collapse
if u implementing viewpager then u can simply use getCount() method to count the no. of pages.

listView stop responding after back from webview

HI, Guys,
I am a newbie, now i am developing a google rss reader for practicing. I used listview to display all the news titles. and webview to view the contents. Every time when i am back from webview, it shows this error:
Error: WebView.destroy() called while still attached!
I overwritten the onBackPressed() in webview activity like this like suggested on codeoverflow:
 @override
public void onBackPressed() {
super.onBackPressed();
if (mWebView != null) {
WebView w = mWebView;
w.removeAllViews();
w.destroy();
w = null;
mWebView = null;
}
}
but it doesn't work. everytime it still shows the same error.
meanwhile, when i am back from the webview, the pressing the items in the main listview doesn't redirect me to the webview activity anymore.
Thanks a lot if someone can give me guidance on this.
reply
crazybeeliuzhe said:
HI, Guys,
I am a newbie, now i am developing a google rss reader for practicing. I used listview to display all the news titles. and webview to view the contents. Every time when i am back from webview, it shows this error:
Error: WebView.destroy() called while still attached!
I overwritten the onBackPressed() in webview activity like this like suggested on codeoverflow:
@override
public void onBackPressed() {
super.onBackPressed();
if (mWebView != null) {
WebView w = mWebView;
w.removeAllViews();
w.destroy();
w = null;
mWebView = null;
}
}
but it doesn't work. everytime it still shows the same error.
meanwhile, when i am back from the webview, the pressing the items in the main listview doesn't redirect me to the webview activity anymore.
Thanks a lot if someone can give me guidance on this.
Click to expand...
Click to collapse
the error i see after scroll is :
at android.support.v4.view.ViewPager.onPageScrolled(ViewPager.java:1708)
at android.support.v4.view.ViewPager.pageScrolled(ViewPager.java:1646)
anyone has similar experience?
I don't know whether the destroy method is needed. However, I recommend to put that code into the onDestroy() method instead of the onBackPressed() method. Might as well solve the problem.
the same problem
nikwen said:
I don't know whether the destroy method is needed. However, I recommend to put that code into the onDestroy() method instead of the onBackPressed() method. Might as well solve the problem.
Click to expand...
Click to collapse
Thanks Nikwen, but it is still the same after i overwritten onDestroy():
 @override
protected void onDestroy() {
super.onDestroy();
if (mWebView != null) {
WebView w = mWebView;
w.removeAllViews();
w.destroy();
w = null;
mWebView = null;
}
int myPid = android.os.Process.myPid();
Log.d(fTag, "exit.myPid = " + myPid);
android.os.Process.killProcess(myPid);
}
seems the problem doesn't come form there.
crazybeeliuzhe said:
Thanks Nikwen, but it is still the same after i overwritten onDestroy():
@override
protected void onDestroy() {
super.onDestroy();
if (mWebView != null) {
WebView w = mWebView;
w.removeAllViews();
w.destroy();
w = null;
mWebView = null;
}
int myPid = android.os.Process.myPid();
Log.d(fTag, "exit.myPid = " + myPid);
android.os.Process.killProcess(myPid);
}
seems the problem doesn't come form there.
Click to expand...
Click to collapse
My first reaction is the same as nikwen's - do you need to do this at all ?
If you do, then it sounds as though the error is arising because your WebView is still attached to something at the point you are attempting to destroy it. So before you can destroy it you'll need to call removeView() on whatever the parent is (probably a layout, I guess).
thanks i will try
PicomatStudios said:
My first reaction is the same as nikwen's - do you need to do this at all ?
If you do, then it sounds as though the error is arising because your WebView is still attached to something at the point you are attempting to destroy it. So before you can destroy it you'll need to call removeView() on whatever the parent is (probably a layout, I guess).
Click to expand...
Click to collapse
Thanks. Then i think i should also call the removeView() before i try to destroy it. I will keep trying and let you guys know my update.
app uploaded
crazybeeliuzhe said:
Thanks. Then i think i should also call the removeView() before i try to destroy it. I will keep trying and let you guys know my update.
Click to expand...
Click to collapse
i have finished my toy app. this is a Google RSS news reader. A good practice for me. You can now download it from google play by searching my name crazybeeliuzhe. you will see two app from me. one is the ipcam viewer i made the other is the news reader.
I will upload my code later to source forge.
your comments are always welcome.

[Q]Service doesn't stop even after calling stopService

Here is the service
Code:
public class SearchService extends IntentService {
public SearchService() {
super("SearchService");
// TODO Auto-generated constructor stub
}
// Binder given to clients
/**
* Class used for the client Binder. Because we know this service always
* runs in the same process as its clients, we don't need to deal with IPC.
*/
[user=439709]@override[/user]
protected void onHandleIntent(Intent intent) {
// TODO Auto-generated method stub
String FILENAME=intent.getStringExtra("name");
String FILEPATH=intent.getStringExtra("path");
ArrayList a=getSearchResult(new File(FILEPATH),FILENAME);
Toast.makeText(this, "Search Completed", Toast.LENGTH_LONG).show();
publishResults(a);
this.stopSelf();
}
private void publishResults(ArrayList<File> outputPath) {
Intent intent = new Intent("notify");
ArrayList<String> a=new ArrayList<String>();
for(int i=0;i<outputPath.size();i++){a.add(outputPath.get(i).getPath());}
intent.putStringArrayListExtra("path", a);
sendBroadcast(intent);
} private void publishResults(String a) {
Intent intent = new Intent("current");
intent.putExtra("name", a);
sendBroadcast(intent);
}}
I am using it like this
Code:
final Intent intent = new Intent(getActivity(), SearchService.class);
intent.putExtra("path",fpath);
intent.putExtra("name",a);
p=new ProgressDialog(getActivity());
p.setCancelable(false);
p.setTitle("Searching Files");
p.setMessage("Please Wait");
p.getWindow().addFlags( WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON );
p.setButton("Cancel", new DialogInterface.OnClickListener(){
public void onClick(DialogInterface p1, int p2)
{
getActivity().stopService(new Intent(getActivity(),SearchService.class));
// TODO: Implement this method
}
});
p.show();
getActivity().startService(intent);
but even after pressing cancel button,broadcast is received in activity
Sent from my GT-S5570 using XDA Premium 4 mobile app
A service to display a toast and brodcast the data it recieved looks like a design flaw
anyways you are extending the intent service i guess it does not implement stopService() rather it stops automatically when it has nothing to do[not sure with it please check documentation for IntentService never actually used one of those ]
I guess you need to extend the Service class from package android.app
Sent from my GT-S5302 using Tapatalk 2
sak-venom1997 said:
A service to display a toast and brodcast the data it recieved looks like a design flaw
anyways you are extending the intent service i guess it does not implement stopService() rather it stops automatically when it has nothing to do[not sure with it please check documentation for IntentService never actually used one of those ]
I guess you need to extend the Service class from package android.app
Sent from my GT-S5302 using Tapatalk 2
Click to expand...
Click to collapse
Actually I am using toast just for debugging.I am learning services. so I might be wrong at places.I made this service to search for files while an indeterminate progress dialog shows in activity till the broadcast of result is received.
I used intentservice because it was supposed to do one work at a time.please suggest me exact ways to use service in my case.I also want to make sure that if activity is paused(minimized) then, when task is completed activity is also started
Sent from my GT-S5570 using XDA Premium 4 mobile app
arpitkh96 said:
Actually I am using toast just for debugging.I am learning services. so I might be wrong at places. I made this service to search for files while an indeterminate progress dialog shows in activity till the broadcast of result is received.
I used intentservice because it was supposed to do one work at a time.please suggest me exact ways to use service in my case.I also want to make sure that if activity is paused(minimized) then, when task is completed activity is also started
Click to expand...
Click to collapse
You can still use an IntentService to do that. To stop it just pass an Intent to it with a boolean extra indicating that you don't want to do anything. You'll need only one more if clause in the onHandleIntent of the service.
SimplicityApks said:
You can still use an IntentService to do that. To stop it just pass an Intent to it with a boolean extra indicating that you don't want to do anything. You'll need only one more if clause in the onHandleIntent of the service.
Click to expand...
Click to collapse
That didnt worked I used it like this.
Code:
@Override
protected void onHandleIntent(Intent intent) {
// TODO Auto-generated method stub
String FILENAME=intent.getStringExtra("name");
String FILEPATH=intent.getStringExtra("path");
boolean b=intent.getBooleanExtra("run",false);
while(b){
ArrayList<File> a=getSearchResult(new File(FILEPATH),FILENAME);
publishResults(a);
this.stopSelf();}
}
Code:
final Intent intent = new Intent(getActivity(), SearchService.class);
intent.putExtra("path",fpath);
intent.putExtra("name",a);
intent.putExtra("run",true);
p=new ProgressDialog(getActivity());
p.setCancelable(false);
p.setTitle("Searching Files");
p.setMessage("Please Wait");
p.getWindow().addFlags( WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON );
p.setButton("Cancel", new DialogInterface.OnClickListener(){
public void onClick(DialogInterface p1, int p2)
{
Intent j=new Intent(getActivity(),SearchService.class);
j.putExtra("run",false);
getActivity().stopService(j);
// TODO: Implement this method
}
});
p.show();
getActivity().startService(intent);
Sent from my GT-S5570 using XDA Premium 4 mobile app
arpitkh96 said:
That didnt worked I used it like this.
Code:
@Override
protected void onHandleIntent(Intent intent) {
// TODO Auto-generated method stub
String FILENAME=intent.getStringExtra("name");
String FILEPATH=intent.getStringExtra("path");
boolean b=intent.getBooleanExtra("run",false);
while(b){
ArrayList<File> a=getSearchResult(new File(FILEPATH),FILENAME);
publishResults(a);
this.stopSelf();}
}
Code:
final Intent intent = new Intent(getActivity(), SearchService.class);
intent.putExtra("path",fpath);
intent.putExtra("name",a);
intent.putExtra("run",true);
p=new ProgressDialog(getActivity());
p.setCancelable(false);
p.setTitle("Searching Files");
p.setMessage("Please Wait");
p.getWindow().addFlags( WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON );
p.setButton("Cancel", new DialogInterface.OnClickListener(){
public void onClick(DialogInterface p1, int p2)
{
Intent j=new Intent(getActivity(),SearchService.class);
j.putExtra("run",false);
getActivity().stopService(j);
// TODO: Implement this method
}
});
p.show();
getActivity().startService(intent);
Click to expand...
Click to collapse
First, if you look in the Dokumentation for IntentService, it says that you should not call stopSelf because it is already implemented to do that when there are no intents left. So It really should be easier to use a Service if you want to stop it like that.
If you want to keep using the intent service, I'd instead use a boolean instance variable which is checked in the publishResults method so just let the service do its work, but before it is published in the UI thread check if the dialog was canceled or not. Otherwise because you have two threads you can't be sure when the other thread receives the boolean change.
To me it seems like you could also use an AsyncTask to handle the threading and that class is easily cancelable .
SimplicityApks said:
First, if you look in the Dokumentation for IntentService, it says that you should not call stopSelf because it is already implemented to do that when there are no intents left. So It really should be easier to use a Service if you want to stop it like that.
If you want to keep using the intent service, I'd instead use a boolean instance variable which is checked in the publishResults method so just let the service do its work, but before it is published in the UI thread check if the dialog was canceled or not. Otherwise because you have two threads you can't be sure when the other thread receives the boolean change.
To me it seems like you could also use an AsyncTask to handle the threading and that class is easily cancelable .
Click to expand...
Click to collapse
I cannot use Asynctask ,as operation could be long.checking the boolean before publish is good idea.I will try this
Sent from my GT-S5570 using XDA Premium 4 mobile app

Categories

Resources