۱۳۹۴/۰۴/۱۵, ۱۰:۴۴ ب.ظ
سلام من یه برنامه با دیتابیس درست کردم و دیتابیس من دو تیبل داره من هر دو تیبل هم تونستم داخل دو اکتویتی جدا گانه بیارم بالا کسی هست راهنمایم کنه چطور میتونم دو تیبل داخل یه اکتویتی اجرا کنم.
package com.androidbegin.sidemenutabstutorial;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.URL;
import java.net.URLConnection;
import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.app.Service;
import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.os.AsyncTask;
import android.os.IBinder;
import android.widget.Toast;
public class MyServic extends Service {
private static final int NOT_ID = 1;
private database db;
private static int b = 0;
@SuppressWarnings("deprecation")
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
db = new database(this);
db.useable();
try {
new DoBackgroundTask("http://refairan.com/getcount.php").execute();
}
catch (Exception e) {
}
Toast.makeText(this, "" + b + "kavos", Toast.LENGTH_LONG).show();
if (b > 0) {
String ns = Context.NOTIFICATION_SERVICE;
NotificationManager mNotificationManager = (NotificationManager) getSystemService(ns);
int icon = R.drawable.ic_action_history;
CharSequence tickerText = " بیمه سامان ";
long when = System.currentTimeMillis();
int requestID = (int) System.currentTimeMillis();
Notification notification = new Notification(icon, tickerText, when);
Context context = getApplicationContext();
Intent notificationIntent = new Intent(this, takhfifat_bime.class);
//notificationIntent.putExtra("data1", "My Data 1");
// notificationIntent.putExtra("data2", "My Data 2");
// notificationIntent.setAction("myString" + requestID);
PendingIntent contentIntent = PendingIntent.getActivity(this, requestID, notificationIntent, 0);
notificationIntent.setData((Uri.parse("mystring" + requestID)));
notification.setLatestEventInfo(context, "Notification Demo", requestID + "", contentIntent);
notification.flags += Notification.FLAG_ONGOING_EVENT;
notification.flags += Notification.FLAG_AUTO_CANCEL;
mNotificationManager.notify(NOT_ID, notification);
b = 0;
} else {
Toast.makeText(this, "kavos" + b, Toast.LENGTH_LONG).show();
}
return Service.START_STICKY;
}
@Override
public IBinder onBind(Intent arg0) {
// TODO Auto-generated method stub
return null;
}
private class DoBackgroundTask extends AsyncTask<URL, Integer, String> {
private String Link = "";
private String countS;
public DoBackgroundTask(String link) {
Link = link;
}
@Override
protected String doInBackground(URL... arg0) {
try {
URL mylink = new URL(Link);
URLConnection connect = mylink.openConnection();
BufferedReader reader = new BufferedReader(new InputStreamReader(connect.getInputStream()));
StringBuilder sb = new StringBuilder();
String line = null;
while ((line = reader.readLine()) != null) {
sb.append(line);
}
countS = sb.toString();
}
catch (Exception e) {
}
return countS;
}
@Override
protected void onPostExecute(String result) {
super.onPostExecute(result);
db.open();
int countL = db.count_inbox("takhfifat_bime");
db.close();
b = Integer.parseInt(result) - countL;
}
}
}
Intent intent = new Intent(this, MyServic.class);
startService(intent);