I wrote an app that most (98%) of the work is done by service.
Where is the best place to do a license check?
In your Main activity, the first time it is launched and where the service is initiated. I wouldn't do it too often so don't put the check into the service.
You could also check periodically, let's say, every 15 minutes.
But don't use Timer for that, as it creates a new thread (well, you could use it, but you could do it in a better way). It's better to use a Handler:
Code:
// Fifteen minutes
int checkFrequency = 15 * 60 * 1000;
Handlerhandler = new Handler();
Runnable runnable = new Runnable() {
[user=439709]@override[/user]
public void run() {
if (!checkLicense()) {
// no license, do whatever you need to do
}
handler.postDelayed(this, checkFrequency);
}
};
handler.postDelayed(runnable, checkFrequency);
So I will check every time he open the main window but the main window is a setup window so it won't be opned so ofen.
you can set preference and check weather user has accepted licence or not and if accepted then no need to display it again .
wasim memon said:
you can set preference and check weather user has accepted licence or not and if accepted then no need to display it again .
Click to expand...
Click to collapse
We've been talking about the Play Store licensing, not about an End User License Agreement.
He wanted to check whether the user has bought his app.
Otherwise your solution would be right though.
11alex11 said:
I wrote an app that most (98%) of the work is done by service.
Where is the best place to do a license check?
Click to expand...
Click to collapse
i would (this is how i do that) check it when the app starts (SplashActivity) and write "encrypted" how often the app got started.
Then everytime when (pseudocode)
if (read_and_decrypt(cntAppStart) % 10) == 0) { checklicense(); }
in the splashactivity.
Related
I´v published my first app on the Android Market. However I have little people in my direct suroundings who have Android Phones so hopefully there are a few people here who can help me by telling my what my application misses.
e.g. I think my app uses little battery power. So maybe anyone can confirm this to me?
becouse i am new to the forum (or .. well not new, but little posts) I can not put the link to my app here. Search on Triton Bubble Breaker on Appbrain or Market to download.
It is a bubble breaker game. Why I developed it when there are other alternatives on the market already? Because I missed the feeling I got when playing it on a old phone for the first time. Wanted to make it faster, simpler, free and maybe add some extra features (that should not be disturbing the simplicity of the game)
(when you are a coder.. I have (maybe a simple) question. When the game is finished I like to save the Score. However I can not do this from a DrawView? only from the main activity, so that i have to use menu buttons to call saving the score... is there a way to save data from view/drawview? )
Thanks in advance, and i wander what you think of my first attempt building a android app.
Good work! Very impressive for a first app!
for saving stuff, use these commands:
(put this at the begining of your class)
public static final String PREFERENCE_FILENAME = "AppGamePrefs";
(put this where you need it, usually located where you are doing the saving)
SharedPreferences gameSettings = getSharedPreferences("MyGamePreferences", MODE_PRIVATE);
SharedPreferences.Editor prefEditor = gameSettings.edit();
(get saved data like this)
score=gameSettings.getInt("score", 0); //"score" is the saved variables name, 0 is the default value incase the variable "score" has not been saved yet
(save like this)
prefEditor.putInt("score", points); // saves to variable "score" with value of variable points (you can change the putInt to putString, putBoolean, etc.)
(this finalizes the save VERY IMPORTANT)
prefEditor.commit();
Hope that helps, keep up the good work!
thanx for the reply. Starting writing in Java (?) was getting used to. I did had some experience with coding in Matlab (if that can be labled programming )
I have tried your advice, I have come across the same code on other fora and samples from google. Only problem is that it doesn't work in the class I am programming in, the drawview class.
In essence my program is setup like this:
public class activity extends Activity
...
public void onCreate(Bundle savedInstanceState) {
...
setContentView(drawView);
...
}
.. some other functions for the menu (from which i can do the code for storing data!)
then it goes into the drawView.
Here my program just draws and draws, until there is a touch on the screen, then it will calculate the new situation. But at a given moment, the game is finished. Then i will draw the finish screen (in the same drawview). I can not get out of this drawview. So i can not do setContentView(results_layout) or something like that. And i can not call the code for saving data because that can not be defined in that class (according to Eclipse).
public class DrawView extends View implements OnTouchListener {
...
@Override protected void onDraw(Canvas canvas) {
Draw everything
...
if game_end = true then {
drawResults
save-code here gives error
}
...
}
public boolean onTouch(View view, MotionEvent event) {
calculate everyting
...
game_end = check_game_end(); //return true or false
}
this is my code in essence. Ofcourse it not all, but this i hope you get my idea/problem.
Thanx for the response again
At it's core... a simple clock app. I'm firing off updates scheduled on each second. On each second, I read the time, then display the time. This is not complicated. And it works, just fine, on my phone. Tick, tick, tick and it looks like a clock. Why wouldn't it, right?
Ok, so the same code on the nook doesn't update regularly. Here's an early video:
http://www.youtube.com/watch?v=URRrYhumt1Y
You can see there's a "double beat". It's like every other update gets displayed for maybe 1.5 seconds. So the overall rate doesn't change, it's still two updates in two seconds, and no updates are missed.
These are being done with a regular myView.setText(), no fancy graphics or anything.
Now, here's more interesting data. If I run the updates twice as often, or five times as often, it changes nothing. I assume the screen/OS is internally detecting no pixels have changed, and so it does nothing. However, if I add, to a totally different view on the screen, an area where I'm toggling from some text to no text (from " " to "+", in actuality, so, a blinking plus sign) AND I run everything at five times a second then the seconds area updates with a steady one hertz beat, just like you would expect from a clock.
Additionally, if I run the code so it only updates every other second, it will click along very predictably at every other second. So it's not a "some code problem with every other update".
I wonder if there's some internal timer in the OS watching for screen updates, and managing them? Perhaps "pushing" the display with a toggling update every 200ms keeps it active and within some timeout limit?
Or are there some nook-specific calls on this?
Cheers,
Anders
I believe that some of the super-duper fast-mode or-whatever-you-call-it throws away some screen updates.
Are you using such a thing or a kernel with such a thing?
No, I'm not attempting any speedy-screen stuff in this code. In the video you can see the grey in the bar, so I'm not in any kind of a 1-bit mode. Because really, one update a second should be no problem.
But if it was throwing away an update... why would the update show up half a second later? I would expect it to skip displaying that second entirely, and so jump to the next.
NoRefresh is installed on this device, but not set to start at boot (and honestly, I don't think I've actually gotten NoRefresh working yet, busy with other things). But I'll uninstall it to be sure and retest.
Is it possible some kind of low-power mode / sleep mode is kicking in? It wakes up half a second later, realizes it has an update, stays away for the next half second, makes the NEXT update (on time) then goes back to sleep after a 0.9ish seconds?
Anders
Yep, even after uninstalling NoRefresh, and rebooting, the behavior is the same. So that's definitely not related.
And running the normal updates to the screen at both 2Hz and 5Hz have the same result, so it's not related to the number of times the updates are called.
Anders
Here's an interesting video... watching the ADB output click along at a clean 1Hz, and the screen updates clearly not synced with the actual writes to the screen.
http://www.youtube.com/watch?v=sL299EUH3T0
Again, all on "stock" system, no special video modes / refresh / magic enabled.
Anders
Actually, I have run into this.
There's no documentation on modes or theory of operating a frame buffer for eInk.
I ran into this on the time display on my audio recorder app.
I ended up using a DL region in my app.
I'll have to look closer into how bad it looks without that.
Are those numbers a TextView or an ImageView?
If it isn't a TextView try one to see if it works better.
There may be slowness in caching/using images.
More questions:
Are you using Timer & TimerTask?
Are you using runOnUiThread?
I wrote a demo app that counts.
It works fine by itself on stock 1.2.1
Renate NST said:
Actually, I have run into this.
There's no documentation on modes or theory of operating a frame buffer for eInk.
I ran into this on the time display on my audio recorder app.
I ended up using a DL region in my app.
I'll have to look closer into how bad it looks without that.
Click to expand...
Click to collapse
DL region? Not familiar with the acronym.
Are those numbers a TextView or an ImageView?
Click to expand...
Click to collapse
It's a text view. Just a big blocky TTF font. (Although the same issue is present using stock fonts).
Are you using Timer & TimerTask?
Are you using runOnUiThread?
Click to expand...
Click to collapse
Using scheduled handlers. They are triggering normally, since A] the ADB output is firing at nice one second intervals, and B] the SystemClock.uptimeMillis shows a 1000 count between each wake up. It's off by one or two millis which is understandable given that it's not a hard-realtime system.
But I'm not familiar with Timer and runOnUiThread, so I'll google those and do some reading.
(In the below code, the "nookPing" area is a tiny spot where I just toggle some pixels. If I do this and run the whole thing at faster than 1Hz, the seconds digit updates on schedule. Turn off this toggling, (which is in a totally unrelated textarea) and back to wonky updates, even at the same update rate. )
Code:
// //////////////////////////////////////////////////////////////////////////////////////////////////
// The Tick task itself /////////////////////////////////////////////////////////////////////////////
// //////////////////////////////////////////////////////////////////////////////////////////////////
private Handler mHandler = new Handler();
private Runnable mUpdateTimeTask = new Runnable() {
public void run() {
Log.d(TAG, "---------------------Tick Called: " +String.valueOf(SystemClock.uptimeMillis()) );
Log.d(TAG, "---------------------");
updateTimeOnScreen();
scheduleNextScreenUpdate();
}
};
// //////////////////////////////////////////////////////////////////////////////////////////////////
// Schedule next update /////////////////////////////////////////////////////////////////////////////
// //////////////////////////////////////////////////////////////////////////////////////////////////
private void scheduleNextScreenUpdate()
{
mHandler.removeCallbacks(mUpdateTimeTask);
mHandler.postAtTime(mUpdateTimeTask,UtilitiesTime.calculateNextScreenUpdateTime());
}
// //////////////////////////////////////////////////////////////////////////////////////////////////
// Show the time ////////////////////////////////////////////////////////////////////////////////////
// //////////////////////////////////////////////////////////////////////////////////////////////////
static int nookPing=0;
private void updateTimeOnScreen() {
String hhmm;
int militaryhours,hour;
int minutes;
int seconds;
int tenths;
int milliseconds;
Calendar rightNow = Calendar.getInstance();
militaryhours=rightNow.get(Calendar.HOUR_OF_DAY);
hour=rightNow.get(Calendar.HOUR);
minutes=rightNow.get(Calendar.MINUTE);
seconds=rightNow.get(Calendar.SECOND);
milliseconds=rightNow.get(Calendar.MILLISECOND);
tenths=milliseconds/100;
SharedPreferences settings = PreferenceManager.getDefaultSharedPreferences(getBaseContext());
if(true==settings.getBoolean("appSettingNookPingActive", false))
{
if(0==nookPing)
{
nookPing=1;
nookPingView.setText(".");
//nookPingView.setText(" ");
}
else{
nookPing=0;
nookPingView.setText(" ");
}
}
else{
nookPingView.setText(" ");
}
if(Configuration.ORIENTATION_PORTRAIT==getScreenOrientation())
{
if(1==MainActivity.appSettingMilitaryTimeFlag)
{
hhmm=String.format(Locale.US,"%02d:%02d",militaryhours, minutes);
}
else{
if(0==hour)
hour=12;
hhmm=String.format("%2d:%02d",hour, minutes);
}
}
else
{
if(1==MainActivity.appSettingMilitaryTimeFlag)
{
hhmm=String.format("%02d\n--\n%02d",militaryhours, minutes);
}
else{
if(0==hour)
hour=12;
hhmm=String.format("%2d\n--\n%02d",hour, minutes);
}
}
int secondsTens=seconds/10;
int secondsOnes=seconds%10;
secondsLeftView.setText(String.format("%d",secondsTens));
secondsRightView.setText(String.format("%d",secondsOnes));
hhmmView.setText(hhmm);
}
HI Guys
This is my first post in android app developement forum.
A small snippet of code which I use to exit from android app .
Many times we have more than one activites in app and often these activities are inter linked.
suppose we have four activities A-> B- ->C->D with A as root activity
Now consider user move from A to B then B--> C then come to A and moves to D
Now when user press back he returns to A
At this some app requires to be close and it should not navigate in history of activity stack ie
going to B then C then again A and finaly exit.
So the solution here is to close the app when user is in A acitivity since its Root activity.
Below is the code for that:
Code:
private static long back_pressed;
private Toast toast;
[user=439709]@override[/user]
public void onBackPressed()
{
if (back_pressed + 2000 > System.currentTimeMillis())
{
// need to cancel the toast here
toast.cancel();
// code for exit
Intent intent = new Intent(Intent.ACTION_MAIN);
intent.addCategory(Intent.CATEGORY_HOME);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);
}
else
{
// ask user to press back button one more time to close app
toast= Toast.makeText(getBaseContext(), "Press once again to exit!", Toast.LENGTH_SHORT);
toast.show();
}
back_pressed = System.currentTimeMillis();
}
Add this code in your root activity so that it wont let app go into history stack.
Also you may write dialog instead of toast message
:good:
Nice snippet, thanks!
Sent from my GT-N7000 using Tapatalk 4
Hi guys,
i've started making an app recently.. and i needed a task to run in the backgound every 2 or 5 minutes.. and i collect the data and i display it when the app is opened.. so am using a sync task.... I'm having a bit of diffculty unerstanding how its used as every example is different..
and FYI am using a seperate .java file to runt he asynctask...
When we go through the android developers page this is the code we see...
They start with
Code:
private class DownloadFilesTask extends AsyncTask<URL, Integer, Long> {
1) whats the deal with the URL Integer Long ????? If i skip it what will happen???
next is this
Code:
protected void onProgressUpdate(Integer... progress) { setProgressPercent(progress[0]);
2) whats the integer doig there?? even if its not used in the function they put it... whats the deal??
3) Also how do we pass values like strings to a class??? i know about functions but the functions used in this class are like a group like so i cant exactly pass values to just one particular function...
Async Task
nvyaniv said:
Hi guys,
i've started making an app recently.. and i needed a task to run in the backgound every 2 or 5 minutes.. and i collect the data and i display it when the app is opened.. so am using a sync task.... I'm having a bit of diffculty unerstanding how its used as every example is different..
and FYI am using a seperate .java file to runt he asynctask...
When we go through the android developers page this is the code we see...
They start with
Code:
private class DownloadFilesTask extends AsyncTask<URL, Integer, Long> {
1) whats the deal with the URL Integer Long ????? If i skip it what will happen???
next is this
Code:
protected void onProgressUpdate(Integer... progress) { setProgressPercent(progress[0]);
2) whats the integer doig there?? even if its not used in the function they put it... whats the deal??
3) Also how do we pass values like strings to a class??? i know about functions but the functions used in this class are like a group like so i cant exactly pass values to just one particular function...
Click to expand...
Click to collapse
Code:
public class async extends AsyncTask<Params , Progress , Result>{
}
here 'params' is the argument that is input to the object of the class...
for eg..
Code:
public class async extends AsyncTask<int , Progress , Result>{
}
then when you will call its object then it will like this.
Code:
public class async extends AsyncTask<int , Progress , Result>{
}
async c;
c.execute(10); // passed int value 10 to execute the async thread in the background...
it has 3 methods that should be implemented
Code:
class load extends AsyncTask<int, Void, Void>{
@Override
protected void onPostExecute(Void result) {
// TODO Auto-generated method stub
// all the ui updation is done here after doing the calculation...
}
@Override
protected void onPreExecute() {
// TODO Auto-generated method stub
super.onPreExecute();
// before the starting of calculation if ui needs to be adjusted then it is done here
}
@Override
protected Void doInBackground(int... arg0) {
// TODO Auto-generated method stub
// all calculation stuf is done here
}
}
IF U WANT SOME MORE HELP REGARDING ASYNC TASK THEN PLZZZ ASK AGAIN....
nvyaniv said:
Hi guys,
i've started making an app recently.. and i needed a task to run in the backgound every 2 or 5 minutes.. and i collect the data and i display it when the app is opened.. so am using a sync task.... I'm having a bit of diffculty unerstanding how its used as every example is different..
and FYI am using a seperate .java file to runt he asynctask...
When we go through the android developers page this is the code we see...
They start with
Code:
private class DownloadFilesTask extends AsyncTask<URL, Integer, Long> {
1) whats the deal with the URL Integer Long ????? If i skip it what will happen???
next is this
Code:
protected void onProgressUpdate(Integer... progress) { setProgressPercent(progress[0]);
2) whats the integer doig there?? even if its not used in the function they put it... whats the deal??
3) Also how do we pass values like strings to a class??? i know about functions but the functions used in this class are like a group like so i cant exactly pass values to just one particular function...
Click to expand...
Click to collapse
OK, so you're probably using it in a service, aren't you?
First of all, carefully read the tutorials here and here on vogella, to help you understand what it does.
1) these are the type of variables that are passed to the respective methods:
An asynchronous task is defined by 3 generic types, called Params, Progress and Result, and 4 steps, called onPreExecute, doInBackground, onProgressUpdate and onPostExecute
Click to expand...
Click to collapse
The Params get passed to the onPreExecute method, the Progress is the one you need to pass calling publishProgress and which is passed to onProgressUpdate. The result one should be returned by your doInBackground method and gets passed to the onPostExecute.
2) the Integer... Is actually an array of the corresponding object to int. Just ignore it and use the progress[0] as if it was a normal int.
3) set your Params variable to String so
AsyncTask <String, Integer, String> if you want to return a string as well
Ok i think i'm getting it... But when we say "Params , Progress , Result" its still a bit confusing..
we first hit pre execute then do iin BG then post execute... But the order in which the params are stated are not the same ...
when i give string first it always takes it for the during BG process... not for the pre execute...
For ex i say asymctask<int, string,void>
so my pre execute should get a int..
then my bg process should get a string..
the post execute should get nothing..
am i right???
nvyaniv said:
Ok i think i'm getting it... But when we say "Params , Progress , Result" its still a bit confusing..
we first hit pre execute then do iin BG then post execute... But the order in which the params are stated are not the same ...
when i give string first it always takes it for the during BG process... not for the pre execute...
For ex i say asymctask<int, string,void>
so my pre execute should get a int..
then my bg process should get a string..
the post execute should get nothing..
am i right???
Click to expand...
Click to collapse
Almost, the Progress variable is passed to the onProgressUpdate. This is something to indicate progress and publish on the UI Thread (for instance update a progress bar), usually an Integer. You can update the Progress from your doInBackground method by calling publishProgress, passing a Progress variable.
The point of this is that the doInBackground method runs in a seperate thread and all other methods run in the UI Thread! So you can't directly pass data between those, only with these values. Consider using a Bundle if you want to pass more than one variable!
public void click(View view) {
String one = "one";
EditText et = (EditText)findViewById(R.id.editText1);
String entered_text = et.getText().toString();
if(et.getText().toString() == one){
TextView tv1 = (TextView)findViewById(R.id.textView1);
tv1.setText("Correct!");
}
else{
TextView tv = (TextView)findViewById(R.id.textView1);
tv.setText(one+entered_text); }
}
This is a code snippet extracted from my program, i didn't post the whole program because it wasn't necessary, as the program runs fine without any runtime exceptions.
So, the program when executed on eclipse doesn't show any errors and runs fine, but when run the "if" condition "et.getText().toString() == "one"" always returns false even when the "entered_text" is "one" i.e.; it never prints "correct!" and the code always prints "one+entered_text" that is the statement in the else clause. And the interesting thing is, if you enter "one" the output will be "oneone", that is the else statement.
Please help me where i went wrong.
Thanks in advance.
You're passing view argument in function so try initialize edit text with (EditText)view.findViewById(R.id.edittext);
panwrona said:
You're passing view argument in function so try initialize edit text with (EditText)view.findViewById(R.id.edittext);
Click to expand...
Click to collapse
Thanks for the reply.
I did what you said and got a runtime exception.
You're running it in fragment or activity?
panwrona said:
You're running it in fragment or activity?
Click to expand...
Click to collapse
Activity.
Are you initializing it in oncreate or somewhere else?
That's easy. Instead of == use text.equals(one)
String are not compared by mathematical signs
Sent from my XT1033 using XDA Premium 4 mobile app