Thursday, 3 October 2013

Android start service on boot, can't receive the broadcast

Android start service on boot, can't receive the broadcast

My service don't start on system boot, only when the user press the
refresh button. I've tried everythng searched in stack but nothing i've
rewrited my code 4 times and nothing, i want my service run in a time
interval and when the refresh button is pressed, i can´t understand why is
not running on boot, Have i missed something?
Manifest.xml
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.android.moody"
android:installLocation="internalOnly"
android:versionCode="0"
android:versionName="0.6.7.2 alpha" >
<permission
android:name="com.android.moody.permission.GET_SERVER_DATA"
android:protectionLevel="normal" />
<uses-sdk
android:maxSdkVersion="18"
android:minSdkVersion="14"
android:targetSdkVersion="17" />
<uses-permission
android:name="com.android.moody.permission.GET_SERVER_DATA" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<application
android:allowBackup="true"
android:allowClearUserData="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name="activities.MainActivity"
android:label="@string/app_name" >
</activity>
<activity
android:name="activities.Menu_esq"
android:label="@string/title_activity_menu_esq" >
</activity>
<activity
android:name="activities.BaseActivity"
android:label="@string/title_activity_base" >
</activity>
<activity
android:name="activities.MainView"
android:label="@string/title_activity_main_view" >
</activity>
<activity
android:name="activities.LoginActivity"
android:label="@string/app_name"
android:noHistory="true"
android:windowSoftInputMode="adjustResize|stateVisible" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name="com.example.moody.LeftActivity"
android:label="@string/title_activity_left" >
</activity>
<activity
android:name="com.example.moody.RightActivity"
android:label="@string/title_activity_right" >
</activity>
<activity
android:name="activities.UserDetailsActivity"
android:label="@string/title_activity_user_details" >
</activity>
<activity
android:name="fragments.FragTopicsPreview"
android:label="@string/title_activity_copy_of_topics_preview" >
</activity>
<activity android:name="activities.LoadingActivity" >
</activity>
<service
android:name="service.ServiceBackground"
android:enabled="true"
android:icon="@drawable/ic_launcher"
android:label="@string/moody_service" >
</service>
<receiver android:name="service.Alarm" >
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
</intent-filter>
</receiver>
<receiver
android:name="service.StartServiceReceiver"
android:permission="com.android.moody.permission.GET_SERVER_DATA" >
<intent-filter>
<action android:name="moody_get_data" />
</intent-filter>
</receiver>
</application>
ServiceBackground
public class ServiceBackground extends Service {
Alarm alarm = new Alarm();
public ServiceBackground() {
// TODO Auto-generated constructor stub
}
private boolean isRunning = false;
Object getContent;
@Override
public IBinder onBind(Intent intent) {
// TODO Auto-generated method stub
return null;
}
@Override
public void onCreate() {
super.onCreate();
// android.os.Debug.waitForDebugger();
}
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
super.onStartCommand(intent, flags, startId);
// Starts the alarm
alarm.setAlarm(getApplicationContext());
// Announcement about starting
Log.d("service", "Service Started");
// Start a Background thread
isRunning = true;
Thread backgroundThread = new Thread(new BackgroundThread());
backgroundThread.start();
return START_NOT_STICKY;
}
@Override
public void onDestroy() {
super.onDestroy();
// Stop the Background thread
isRunning = false;
}
private class BackgroundThread implements Runnable {
public void run() {
try {
while (isRunning) {
Log.d("service", "Thread started");
new ManContents().getAll(getResources(),
getApplicationContext());
isRunning = false;
}
stopSelf();
} catch (Exception e) {
e.printStackTrace();
}
}
}
Alarm
public class Alarm extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
context.startService(new Intent(context, ServiceBackground.class));
}
public void setAlarm(Context context) {
String alarm = Context.ALARM_SERVICE;
AlarmManager am = (AlarmManager) context.getSystemService(alarm);
Intent intent = new Intent("moody_get_data");
PendingIntent pi = PendingIntent.getBroadcast(context, 0, intent, 0);
int type = AlarmManager.ELAPSED_REALTIME_WAKEUP;
// long interval = AlarmManager.INTERVAL_FIFTEEN_MINUTES;
long interval = 1000 * 60 * 2;
long triggerTime = SystemClock.elapsedRealtime() + interval;
am.setRepeating(type, triggerTime, interval, pi);
}
public void CancelAlarm(Context context) {
Intent intent = new Intent(context, Alarm.class);
PendingIntent sender = PendingIntent
.getBroadcast(context, 0, intent, 0);
AlarmManager alarmManager = (AlarmManager) context
.getSystemService(Context.ALARM_SERVICE);
alarmManager.cancel(sender);
}
}
StartServiceReceiver
public class StartServiceReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
Log.d("service", "Starting service from serviceReceiver");
Intent service = new Intent(context, ServiceBackground.class);
context.startService(service);
}
}
NOTES:
i already tried starting the service directly without filters, but for no
reason don't start, so with filters was the only way that worked.
I also tried without the StartServiceReceiver.java, with the intent inside
the alarm but no luck, i can change the code again if somebody thinks that
its the problem.
I've the while(isRunning) in the thread only for future purpose, but i
think the problem it's not because this.

Wednesday, 2 October 2013

iOS 7 viewDidLoad executes slowly while pushing viewcontroller

iOS 7 viewDidLoad executes slowly while pushing viewcontroller

I was trying to push a viewcontroller B into navigation controller from A
and then assigning some properties of B in A. In this case, assigning of
properties was done and then viewDidLoad of viewcontroller A was executed.
Here, assigning properties in A should be done only after viewDidLoad of A
has done. For example,
[b.navController pushViewController:a animated:YES]; a.status = @"loaded";
Here status was assigned first and then viewDidLoad of A was executed.
This happens only in iOS 7 where as in iOS6 it works fine.
Can any one please let me know where was the problem?
Thank you.

Pass the location of a file to a method in java?

Pass the location of a file to a method in java?

I'm trying to create an object that gets the location and sets an
jEditorPane to the contents of the located file.
Code:
File file = new File("Summary.html");
private void EditoPaneMethod(File file) {
frmRules.pack();
frmRules.setVisible(true);
edpRules.setEditable(false);
try {
edpRules.setPage(file.toURI().toURL());
} catch (IOException ex) {
Logger.getLogger(MainMenu.class.getName()).log(Level.SEVERE, null,
ex);
}
}
Could someone point me in the right direction?

uncaught TypeError on savebutton

uncaught TypeError on savebutton

I was haveing problems with a save button on a website i am working on. i
get this error in chrome: Uncaught TypeError: Cannot read property
'contentWindow' of undefined
and this error in firefox: TypeError:
$(...).children(...).children(...).children(...)[3] is undefined
here is the pice of code where the error is located:
$('.btnAddProduct').click(function(){
if(busy != 1){
busy = 1;
var error = 0;
if($('input[name="txtTitle"]').val() == ''){
error = 1;
alert('Het titel veld is nog leeg');
$('input[name="txtTitle"]').focus();
}
if(error != 1){
$('.content_load_icon').html('<img
src="../../includes/images/layout/load_small.gif" />');
var content =
$('#cke_ckeditor').children().children().children()[3].contentWindow.document.childNodes[1].childNodes[1].innerHTML;
$.ajax({
url: '../../action/ac_productbeheer.php?a=add',
type: 'POST',
data: {txtTitle: $('input[name="txtTitle"]').val(),
txtParentPage: $('select[name="txtParentProduct"]').val(),
txtContent: content, create: true},
success: function(data, textStatus, xhr) {
$('.content_load_icon').html('');
$('.txtContentConsole').html('Product succesvol
opgeslagen!').show().delay(2000).fadeOut(200);
busy = 0;
saved = 1;
window.location =
'../../modules/productbeheer/index.php';
},
error: function(xhr, textStatus, errorThrown) {
$('.content_load_icon').html('');
$('.txtContentConsole').html('Fout bij opslaan!
Probeer het later nog een
keer.').show().delay(2000).fadeOut(200);
busy = 0;
}
});
} else {
error = 0;
busy = 0;
}
}
});
I hope one of you guys/girls can help me with this problem.

Tuesday, 1 October 2013

getSubmittedValue() is coming null jsf

getSubmittedValue() is coming null jsf

I facing one problem in jsf, when i attached to my , as shown below
<h:inputText id="" value="" binding="">
<a4j:support
actionListener="Action_Class.validateUserName"
event="onblur" />
</h:inputText>
As shown in above, when i am tabbing out from field, validateUserName has
to call.it is calling,but when i am trying to get my submitted value as
shown below, null is coming. UIInput input = actionEvent.getParent();
String userName = input.getSubmittedValue(); username is coming as
null.(The submitted value is coming only in IE browser, but in remaining
browsers i am getting null as submitted value). Kindly do needful.

MySQL Design For High Frequency Billing System

MySQL Design For High Frequency Billing System

I have a feeling I'm gonna get butchered for asking this question, but
here it goes...
I have 5 million daily subscriptions & expect/hope to have 50million in 12
months. I need to renew/bill these very, very quickly. I've tried every
permutation of index & looping I could think of, but its the SELECT
queries are still too slow. Perhaps my mistake is MySQL design, perhaps
its my daemon that uses MySQL, perhaps its simply because I'm using MySQL
- please let me know your thoughts and/or advice. Thanks!
** Subscription Table looks like this **
subscription_id (PK)
subscriber_id
service_id
add_date
current_period_start_date
current_period_end_date
next_bill_date (used to ensure two threads dont grab to bill at same time)
last_successful_bill_date
has_outstanding_balance
** Money-people-owe-me table looks like this *
id
subscription_id (UK)
outstanding_balance
next_bill_date
number_bill_attempts
(a fair amount of people dont always pay, I give them unpaid access for a
bit while I continue trying to bill, eventually I cut off their service
though)
** Billing Daemon looks like this **
Run multi-threaded on multiple machines, here is the master thread:
For each service
stuffToBill[] = SELECT stuff ORDER BY next_bill_date FOR UPDATE LIMIT XXX;
UPDATE stuff SET next_bill_date = later WHERE id IN (stuffToBill[ids])
COMMIT
Put them on a queue for billing workers
Running EXPLAIN shows that I'm using decent indexing, but nitty gritty of
the SQL combined with the fact that I am running the same daemon on
multiple servers makes it lock up / generally overload the I/O queue on my
DBM. DBM is quality hardware.
Thanks again for your advice!

slow server when page have mysql

slow server when page have mysql


my server now works very fast in non mysql requests , example:
http://download.saqafa.com/
but when it come to more mysql requests it be very slow and take more time
to load , i don't know the reason , my server is I5 with 12 GB rams
example of slow page :
http://www.saqafa.com/article/8434