我正试图在启动时启动我的kivy应用程序服务.
我确信我的服务还可以,因为它可以在我启动应用程序时运行.但是在启动时我遇到了问题.
我已经阅读了这篇文章并尝试制作它:
package net.saband.myapp;
import android.content.BroadcastReceiver;
import android.content.Intent;
import android.content.Context;
import org.kivy.android.PythonActivity;
public class MyBroadcastReceiver extends BroadcastReceiver {
public void onReceive(Context context, Intent intent) {
Intent ix = new Intent(context, PythonActivity.class);
ix.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(ix);
}
}
Run Code Online (Sandbox Code Playgroud)
它可以工作,但启动应用程序,但不启动服务.所以我在StackOverflow上研究了一些问题并改变了我的代码:
package net.saband.myapp;
import android.content.BroadcastReceiver;
import android.content.Intent;
import android.content.Context;
import net.saband.myapp.ServiceMyservice;
public class MyBroadcastReceiver extends BroadcastReceiver {
public void onReceive(Context context, Intent intent) {
Intent ix = new Intent(context, ServiceMyservice.class);
ix.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startService(ix);
}
}
Run Code Online (Sandbox Code Playgroud)
......并收到错误:
10-21 19:16:44.784 1513 1569 I ActivityManager: Start …Run Code Online (Sandbox Code Playgroud) 我注意到我的应用程序中的小部件创建速度很慢,所以我创建了这个简单的测试应用程序来检查它。它包含两个屏幕,每个屏幕都包含简单的小部件列表。
应用程序:
from kivy.app import App
from kivy.uix.screenmanager import ScreenManager, Screen
from kivy.uix.boxlayout import BoxLayout
from kivy.properties import ObjectProperty, StringProperty
from kivy.clock import Clock
from time import time
class ListScreen(Screen):
items_box = ObjectProperty(None)
def on_enter(self):
start = time()
for i in range(0,50):
self.items_box.add_widget(ListItem('Item '+str(i)))
self.items_box.bind(minimum_height=self.items_box.setter('height'))
print time()-start
def on_leave(self):
self.items_box.clear_widgets()
class ListItem(BoxLayout):
title = StringProperty('')
def __init__(self, title, **kwargs):
super(ListItem, self).__init__(**kwargs)
self.title = title
class ListApp(App):
sm = ScreenManager()
screens = {}
def build(self):
self.__create_screens()
ListApp.sm.add_widget(ListApp.screens['list1'])
Clock.schedule_interval(self._switch, 1)
return ListApp.sm …Run Code Online (Sandbox Code Playgroud)