小编Jay*_*ayB的帖子

活动结束时服务停止

我已经阅读了一些与这个问题相关的答案,它们似乎都是一样的:

"使用START_STICKY运行您的服务"
"在前台
运行您的服务" "使用startService运行您的服务,不要绑定它"

我正在做所有这些事情,我的服务STILL关闭并在每次关闭活动时重新启动.

这不是IntentService.我也没有在onClick处理程序中调用stopSelf或stopService.

请向下滚动到我的更新 - 此行为已被确认为Android操作系统中的错误,我已将其报告给谷歌. 点击此处查看报告.

从MainActivity启动我的服务:

svcIntent = new Intent(getBaseContext(), MyService.class);
startService(svcIntent);
Run Code Online (Sandbox Code Playgroud)

在我的onStartCommand中:

        // Enter foreground state
    String title = "Service has been started...";
    String subject = "Service is running...";
    String body = "Monitoring your battery usage.";
    Notification notification = new Notification(R.drawable.theicon, title,
            System.currentTimeMillis());
    if (prefs.getBoolean("notificationSounds", true))
        notification.defaults |= Notification.DEFAULT_SOUND;
    else
        notification.sound = null;
    Intent notificationIntent = new Intent(this, MainActivity.class);
    PendingIntent pendIntent = PendingIntent.getActivity(this, 0, notificationIntent, 0);
    notification.setLatestEventInfo(this, subject, body, pendIntent);
    startForeground(1500, notification);
Run Code Online (Sandbox Code Playgroud)

在我的onStartCommand结束时: …

java android android-intent android-service android-activity

5
推荐指数
1
解决办法
1729
查看次数

在下推自动机中以相反的顺序推送/弹出堆栈

所以我正在研究我已经提出的下推自动机和无上下文语言的测试,我坚持这个结构.

我让这个自动机的每个部分都完全正常工作,除了我将在下面解释的一个部分.

它需要识别的语言是:{x#y#z#w | x,y,z,w在{0,1} +中,其中x≠w且y≠z}.

所以我遇到的问题是将Xi与Wi进行比较,因为Wi的元素在自动机处理W时是不知道的,就像我设计的那样.

如果我存储X的内容,当弹出时间并将每个元素与W的元素进行比较时,它们将以相反的顺序弹出,因此认为000111和111000是相同的字符串,而PDA将拒绝,当它应该明确接受(它们是不同的字符串).这只是一个例子,这也会导致错误地分析其他输入.

如果有一种方法可以按相反的顺序将X的内容压入堆栈,它们将以原始形式弹出,这样我就可以正确地比较字符串的内容.

如果在正常推送后有一种方法可以反转堆栈的内容,这也可以让我得出解决方案.

任何帮助将不胜感激.谢谢.

automata non-deterministic pushdown-automaton automata-theory

5
推荐指数
1
解决办法
1872
查看次数

CFileDialog实例化的问题

我正在遵循这个定义CFileDialog,但VS2013仍然告诉我没有构造函数可用于我传入的参数.

我的代码:

CFile theFile;
char strFilter[] = { "TXT Files (*.txt)|*.txt|All Files (*.*)|*.*||" };
CFileDialog fDlg = CFileDialog(TRUE, ".txt", NULL, 0, strFilter);
Run Code Online (Sandbox Code Playgroud)

结果错误:

1 IntelliSense:没有构造函数实例"CFileDialog :: CFileDialog"匹配参数列表参数类型是:(int,const char [5],int,int,char [46])c:\ Users\Jonathan\Documents\Visual Studio 2013\Projects\SDI\SDI\MainFrm.cpp 131 21 SDI

CFileDialog构造函数供参考:

explicit CFileDialog(BOOL bOpenFileDialog, // TRUE for FileOpen, FALSE for FileSaveAs
    LPCTSTR lpszDefExt = NULL,
    LPCTSTR lpszFileName = NULL,
    DWORD dwFlags = OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT,
    LPCTSTR lpszFilter = NULL,
    CWnd* pParentWnd = NULL,
    DWORD dwSize = 0,
    BOOL bVistaStyle = …
Run Code Online (Sandbox Code Playgroud)

c++ mfc cfiledialog

4
推荐指数
1
解决办法
1558
查看次数

试图传递CStringArray给出错误无法访问类'CObject'中声明的私有成员

我收到一个奇怪的错误告诉我,当我只是尝试将CS​​tringArray传递给我编写的函数以将其分解为碎片时,我无法访问在类'CObject'中声明的私有成员.我已经注释掉了我的整个函数代码,所以我知道问题存在于对象本身的传递中,我假设我做错了.

这是我的代码:

    // If successful, read file into CStringArray
    CString strLine;
    CStringArray lines;
    while (theFile.ReadString(strLine))
    {
        lines.Add(strLine);
    }

    // Close the file, don't need it anymore
    theFile.Close();

    // Break up the string array and separate it into data
    CStringArrayHandler(lines);
Run Code Online (Sandbox Code Playgroud)

这是我的CStringArrayHandler函数:

void CSDI1View::CStringArrayHandler(CStringArray arr)
{
    // Left out code here since it is not the cause of the problem
}
Run Code Online (Sandbox Code Playgroud)

这是我的头文件中的函数声明:

class CSDI1View : public CView
{
// Operations
public:
    void CStringArrayHandler(CStringArray arr);   // <<<<===================
Run Code Online (Sandbox Code Playgroud)

这是我得到的错误的全文:

错误1错误C2248:'CObject :: CObject':无法访问在类中声明的私有成员>'CObject'c:\ program files(x86)\ …

c++ mfc compiler-errors cstring visual-studio-2013

3
推荐指数
1
解决办法
1157
查看次数

Hoare的分区无法正常工作(快速排序)

因此,遵循Cormen的quicksort和hoares分区算法之后,这就是我能够生成的代码。数组出来的部分内容是未初始化的元素/垃圾元素,我一辈子都无法弄清楚为什么……我以为我完全按照书中的描述遵循算法。

这是本书中的伪代码:

HOARE-PARTITION(A, p, r)
1 x = A[p]
2 i = p - 1
3 j = r + 1
4 while TRUE
5     repeat
6        j = j - 1
7     until A[j] <= x
8     repeat
9        i = i + 1
10    until A[i] >= x
11    if i < j
12        exchange A[i] with A[j]
13    else return j
Run Code Online (Sandbox Code Playgroud)

这是我将其翻译成的C ++代码:

void quickSort(int arr[], int p, int r){
    if(p < r){
        int q = hoare_partition(arr, …
Run Code Online (Sandbox Code Playgroud)

c++ algorithm quicksort

1
推荐指数
1
解决办法
2685
查看次数